//不多说直接上代码
int[] a={1,3,4};
/**下面是将基本数组转化为对象数组*/
Integer[] ib= IntStream.of(a).boxed().collect(Collectors.toList()).toArray(new Integer[0]);
System.out.println(Arrays.toString(ib)); // [1, 3, 4]
//需要注意的是强转不是(Integer[]) ,具体原因百度就知道了
/**基本数组转为List就更简单了,去掉toArray即可*/
List<Integer> ls=IntStream.of(a).boxed().collect(Collectors.toList())
System.out.println(ls); //[1, 3, 4]
Java中用一条语句把基础类型(int)数组转为对象数组(Integer),或者变为List
最新推荐文章于 2025-07-23 08:49:38 发布
