Last active
October 5, 2018 06:16
-
-
Save geekoff7/b03968cbbf68793a7f927e08610443f2 to your computer and use it in GitHub Desktop.
ArrayToListAndListToArray
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.ArrayList; | |
| import java.util.Arrays; | |
| import java.util.Collections; | |
| import java.util.List; | |
| import java.util.stream.Collectors; | |
| public class Main { | |
| public static void main(String[] args) { | |
| Integer[] array = new Integer[] { 1, 2, 3, 4 }; | |
| List<Integer> list = new ArrayList<>(); | |
| // list = Arrays.asList(array); | |
| // list = Arrays.stream(array).collect(Collectors.toList()); | |
| Collections.addAll(list, array); | |
| Integer[] array2 = new Integer[list.size()]; | |
| array2 = list.toArray(array2); | |
| for (Integer i : array2) { | |
| System.out.println(i); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment