The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.util  [50 examples] > Collections  [7 examples]

e342. Implementing a Queue

    LinkedList queue = new LinkedList();
    
    // Add to end of queue
    queue.add(object);
    
    // Get head of queue
    Object o = queue.removeFirst();
    
    // If the queue is to be used by multiple threads,
    // the queue must be wrapped with code to synchronize the methods
    queue = (LinkedList)Collections.synchronizedList(queue);

 Related Examples
e343. Implementing a Stack
e344. Implementing a Least-Recently-Used (LRU) Cache
e345. Listing the Elements of a Collection
e346. Storing Primitive Types in a Collection
e347. Creating a Copy of a Collection
e348. Making a Collection Read-Only

See also: Arrays    Bits    Dates    Hash Tables    Lists    Property Files    Sets    Sorted Collections    Time    Timers   


© 2002 Addison-Wesley.