Skip to content

Instantly share code, notes, and snippets.

@adojos
Last active March 9, 2023 11:09
Show Gist options
  • Save adojos/b94cd55a7f9a58d8177ce6abc34bb9e9 to your computer and use it in GitHub Desktop.
Save adojos/b94cd55a7f9a58d8177ce6abc34bb9e9 to your computer and use it in GitHub Desktop.
Java: Convert List to Array : Stream with param #java
public static void convertUsingStream2() {
List<Integer> inputList = Arrays.asList(2, 4, 6, 8, 10);
Stream<Integer> inputStream = inputList.stream();
Integer[] intArray = inputStream.toArray((num) -> new Integer[num]);
//print the elements in the array
for (int num : intArray) {
System.out.print(num + " ");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment