Skip to content

Instantly share code, notes, and snippets.

@geekoff7
Last active October 5, 2018 06:16
Show Gist options
  • Select an option

  • Save geekoff7/b03968cbbf68793a7f927e08610443f2 to your computer and use it in GitHub Desktop.

Select an option

Save geekoff7/b03968cbbf68793a7f927e08610443f2 to your computer and use it in GitHub Desktop.
ArrayToListAndListToArray
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