What is the fastest way to convert a Queue
into a List
while keeping the Queue order?
Answering to old question for users who are already on java 8
Java 8 provides the option of using streams and you can get a list from queue as:
For example:
Queue queue = new LinkedList<>();
Student s1 = new Student("A",2);
Student s2 = new Student("B",1);
Student s3 = new Student("C",3);
queue.add(s1);
queue.add(s2);
queue.add(s3);
List studentList = queue.stream().collect(Collectors.toCollection(ArrayList::new));