Java LinkedList.toArray()
Syntax
LinkedList.toArray() has the following syntax.
public Object [] toArray()
Example
In the following code shows how to use LinkedList.toArray() method.
/*from w w w.j a v a2 s. com*/
import java.util.Arrays;
import java.util.LinkedList;
public class Main {
public static void main(String[] args) {
LinkedList<String> list = new LinkedList<String>();
list.add("Hello");
list.add("from java2s.com");
list.add("java tutorial");
// print the list
System.out.println("LinkedList:" + list);
// create an array and copy the list to it
Object[] array = list.toArray();
System.out.println(Arrays.toString(array));
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.util »
Java Tutorial »
java.util »