Java Reference
In-Depth Information
A deque (pronounced “deck”) is a double-ended queue that allows for elements to be
inserted and removed at both ends of the queue. Deques implement the Deque interface, a
subinterface of Queue . Figure 7.4 shows the hierarchy of queue interfaces and classes.
FIGURE 7.4 The Queue and Deque interfaces and implementing classes
interface
Queue
class
PriorityQueue
interface
Deque
class
LinkedList
class
ArrayDeque
The different queue and deque classes each have their own specifi c behaviors:
PriorityQueue A queue where the elements are ordered based on an ordering you specify
(as opposed to ordering based on FIFO).
LinkedList The same LinkedList class we saw earlier in the discussion on lists.
LinkedList also implements the Queue and Deque interfaces, providing a queue or deque
that is implemented as a linked list data structure.
ArrayDeque A queue and deque implemented as a resizable array with no capacity
restrictions.
The basic operations of Queue include adding a single element, polling the queue to
retrieve the next element, or peeking at the queue to see if there is an element available
in the queue. The Deque operations are similar except elements can be added, polled, or
peeked at both the beginning and end of the deque.
Maps
A map is a collection that maps keys to values. Each key maps to one value, and duplicate
keys are not allowed in a map. A map is similar to a function in mathematics. Use a map
when the data you are storing has a key value that is more meaningful than a simple integer
index (like arrays and lists use). For example, suppose you need to write a phonebook
application. A person's name and phone number are paired together, and we usually search a
phonebook by a person's name. Therefore, a phonebook map could use a person's name as
the key and their phone number as the value of that key.
Figure 7. 5 shows the Map interface, its subinterfaces, and the various map classes in the
Collections Framework.
Search WWH ::




Custom Search