Convert a LinkedList to ArrayList
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class Main {
public static void main(String[] args) {
LinkedList<String> myQueue = new LinkedList<String>();
myQueue.add("A");
myQueue.add("B");
myQueue.add("C");
myQueue.add("D");
List<String> myList = new ArrayList<String>(myQueue);
for (Object theFruit : myList)
System.out.println(theFruit);
}
}
Output:
A
B
C
D
Home
Java Book
Runnable examples
Java Book
Runnable examples
Collection LinkedList:
- Add value to the first position in a linked list
- Convert a LinkedList to ArrayList
- Remove first and last elements of LinkedList Java example