Skip to content

Instantly share code, notes, and snippets.

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