将String[] 转成List<Integer>

将String[] 转成List<Integer>

public static void main(String[] args) throws Exception
{
String num= "1,2,3,4,5,6";
String[] statusArr = num.split(",");
int[] ints = Arrays.asList(statusArr).stream().mapToInt(Integer::parseInt).toArray();
List<Integer> collectNumber = Arrays.stream(ints).boxed().collect(Collectors.toList());

 

第二种方法

String[] statusArr = num.split(",");
List<Integer> statusNumber = Stream.of(statusArr).map(Integer::parseInt).collect(Collectors.toList());


}

posted @ 2022-07-15 12:02  xiao-jie-tian  阅读(1157)  评论(0)    收藏  举报