Convert a Queue to a List : Queue « Collections Data Structure « Java






Convert a Queue to a List

     
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
*/

   
    
    
    
    
  








Related examples in the same category

1.Priority queuePriority queue
2.Queue data structureQueue data structure
3.Create a queue using LinkedList class
4.Simple Queue (FIFO) based on LinkedList
5.The Generic Queue Class
6.Blocking Queue
7.Circular Queue
8.Circular Queue extends AbstractList
9.How to extend the collections framework
10.An unbounded {@link TransferQueue} based on linked nodes.
11.This class implements the data structures necessary for an ArrayQueue
12.A circular queue from mina
13.An unbounded TransferQueue based on linked nodes.
14.Rotating queue of fixed size.
15.Allows threads to communicate asynchronously by putting messages into and reading messages out of a synchronized queue.