String ids = “1,2,3”;
// 方法一
List<Integer> list1 = Arrays.asList(ids.split(",")).stream().map(s -> Integer.parseInt(s.trim())).collect(toList());
list1.forEach(System.out::println);
System.out.println("------------------------------分割线------------------------------");
// 方法二
List<Integer> list3 = Arrays.stream(ids.split(",")).map(Integer::parseInt).collect(toList());
for (Integer integer : list3) {
System.out.println(integer);
}
打印输出