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);
}
}
}
Latest posts by Wayan (see all)
- How do I create a string of repeated characters? - September 1, 2023
- How do I convert datetime string with optional part to a date object? - August 28, 2023
- How do I split large excel file into multiple smaller files? - April 15, 2023