记录数组转集合(int[]转list)的快速方法,数组转list必须先将数组转为list,int[]转list有问题,不能用,integer[]转list可以使用。

 

用arrays.aslist()有问题     数组一行代码转list

int[] nums = {1,1,1,2,2,2};
List<Integer> li = Arrays.stream( nums ).boxed().collect(Collectors.toList());

int[]只有先转list才可以转set   set不转list可以用iterate迭代取值,也可以转list后取值

int[] nums = {1,1,1,2,2,2};
List<Integer> collect = Arrays.stream(nums).boxed().collect(Collectors.toList());
HashSet<Integer> t = new HashSet<>(collect );
LinkedList<Integer> list = new LinkedList<>(t);

 

posted @ 2020-05-14 16:56  小城熊儿  阅读(416)  评论(0编辑  收藏  举报