在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]
热门推荐
10 祝女儿简短祝福语大全
11 大学新年祝福语简短创意
12 元旦适合的祝福语简短
13 朋友出远门祝福语简短
14 初六简短的祝福语
15 祝男孩生日祝福语简短
16 同事调离的祝福语简短
17 拜年红包的祝福语简短
18 妈妈生日祝福语简短励志