将 Java 中的字符串列表转换为整数列表的程序
以下是我们的字符串列表 −
List<String> listString = Arrays.asList("25", "50", "75", "100", "125", "150");现在,将字符串列表转换为整数列表 −
List<Integer> listInteger = listString.stream().map(Integer::parseInt).collect(Collectors.toList());
以下是将 Java 中的字符串列表转换为整数列表的程序 −
示例
import java.util.*;
import java.util.stream.*;
import java.util.function.*;
public class Demo {
public static void main(String[] args) {
List<String> listString = Arrays.asList("25", "50", "75", "100", "125", "150");
System.out.println("List of String = " + listString);
List<Integer> listInteger = listString.stream().map(Integer::parseInt)
.collect(Collectors.toList());
System.out.println("List of Integer (converted from List of String) = " + listInteger);
}
}输出
List of String = [25, 50, 75, 100, 125, 150] List of Integer (converted from List of String) = [25, 50, 75, 100, 125, 150]
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP