Skip to content

Instantly share code, notes, and snippets.

@adojos
Last active March 9, 2023 11:09
Show Gist options
  • Save adojos/c64fb3f325d991fc7f1cb98eb0f652a0 to your computer and use it in GitHub Desktop.
Save adojos/c64fb3f325d991fc7f1cb98eb0f652a0 to your computer and use it in GitHub Desktop.
Java: Convert List to Array : For-Loop #java
public static void convertUsingForLoop(){
List<Integer> inputList = Arrays.asList(2,4,6,8,10);
int[] outputArray = new int[inputList.size()];
for(int i = 0; i < inputList.size();i++){
outputArray[i] = inputList.get(i);
}
//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