Java 数组和集合的相互转换

        System.out.println("-----数组转list-----");
        String[] strs1 = new String[] {"1", "2", "3"};
        List asList = Arrays.asList(strs1);

        asList.forEach(s -> System.out.println(s));

        System.out.println("---List 转 数组-----");
        List numbers = new ArrayList<>();
        numbers.add("1");
        numbers.add("2");
        numbers.add("2");
        String[] strs2 = new String[numbers.size()];

        numbers.toArray(strs2);

        for (String string : strs2) {
            System.out.println(string);
        }

输出:

-----数组转list-----
1
2
3
---List 转数组-----
1
2
2

你可能感兴趣的:(Demo)