Convert a Queue to a List : Queue « Collections « Java Tutorial






import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

public class Main {
  public static void main(String[] args) {
    Queue<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);
  }
}
/*
A
B
C
D
*/








9.14.Queue
9.14.1.Convert a Queue to a List
9.14.2.Use the Stack class in Java
9.14.3.Create a queue using LinkedList class
9.14.4.Checking what item is first in line without removing it: element
9.14.5.A Priority Queue
9.14.6.Binary Heap Queue
9.14.7.Circular Queue
9.14.8.Synchronized Queue