@Test public void test5(){ int[] array = {1, 2, 5, 5, 5, 5, 6, 6, 7, 2, 9, 2}; /*int[]转list*/ //方法一:需要导入apache commons-lang3 jar List<Integer> list = Arrays.asList(ArrayUtils.toObject(array)); //方法二:java8及以上版本 List<Integer> list1 = Arrays.stream(array).boxed().collect(Collectors.toList()); /*list转int[]*/ //方法一: Integer[] intArr = list.toArray(new Integer[list.size()]); //方法二:java8及以上版本 int[] intArr1 = list.stream().mapToInt(Integer::valueOf).toArray(); }
转载至https://blog.csdn.net/qq493820798/article/details/100894596