int[] nums;
List<Integer> List=Arrays.stream(nums).boxed().collect(Collectors.toList());
如果是其他类型,可以直接asList
String[] s;
List<String> list=Arrays.asList(s);
List转 int[]就简单多了
List<Integer> list=new ArrayList<>();
list.stream().mapToInt(Integer::valueOf).toArray();
本文介绍了如何在Java中轻松地将数组转换为列表,以及如何将列表转换回数组的方法。对于int数组,使用stream和boxed方法可以将其转换为Integer列表。而其他类型的数组可以直接使用asList方法。反之,将列表转换为int数组则需使用stream和mapToInt方法。

379

被折叠的 条评论
为什么被折叠?



