How to convert LinkedList to array in Java? Example

You can convert a LinkedList to an array in Java by using the toArray() method of LinkedList. The toArray() method accepts an array of relevant type to store contents of LinkedList. It stores the elements in the same order they are currently inside LinkedList. By using the toArray() method you can convert any type of LinkedList e.g. Integer, String or Float to any type of Array, only catch is this you cannot convert a LinkedList to an array of primitives i.e. a LinkedList of Integer cannot be converted into an array of ints by using using toArray() method, but you can convert it to array of Integer objects, that's perfectly ok. Similarly, you can convert LinkedList of Double to an array of Double and LinkedList of Float objects to an array of floats.
Read more »