Skip to content

Instantly share code, notes, and snippets.

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