Core API
How do I convert LinkedList to array?
package org.kodejava.util; import java.util.LinkedList; import java.util.List; public class LinkedListToArray { public static void main(String[] args) { List<String> list = new LinkedList<>(); list.add("Blue"); list.add("Green"); list.add("Purple"); list.add("Orange"); // Converting LinkedList to array can be done by calling the toArray() // method of the List; String[] colors = new String[list.size()]; list.toArray(colors); for (String color : colors) { System.out.println("c...
Article by Wayan · Source: Kode Java ↗
package org.kodejava.util;
import java.util.LinkedList;
import java.util.List;
public class LinkedListToArray {
public static void main(String[] args) {
List<String> list = new LinkedList<>();
list.add("Blue");
list.add("Green");
list.add("Purple");
list.add("Orange");
// Converting LinkedList to array can be done by calling the toArray()
// method of the List;
String[] colors = new String[list.size()];
list.toArray(colors);
for (String color : colors) {
System.out.println("color = " + color);
}
}
}
Comments 0
Share your questions, experiences, or feedback about this article.
Sign in with Google to leave a comment.
Sign in with Google
No comments yet. Be the first to share your feedback.