Java collections framework: Difference between revisions

Content deleted Content added
added references
added Queue interface
Line 12:
==List Interface==
Lists are implemented in the JCF via the List interface. It defines a list as essentially a more flexible version of an array. Elements have a specific order, and duplicate elements are allowed. Elements can be placed in a specific position. They can also be searched for within the list. Two concrete classes implement List. The first is ArrayList, which implements the list as an array. Whenever functions specific to a list are required, the class moves the elements around within the array in order to do it. The other implementation is LinkedList. This class stores the elements in nodes that each have a pointer to the previous and next nodes in the list. The list can be traversed by following the pointers, and elements can be added or removed simply be changing the pointers around to place the node in its proper place.<ref>http://download.oracle.com/javase/6/docs/api/java/util/List.html</ref>
 
==Queue Interface==
The Queue interface defines the queue data structure, which stores elements in the order in which they are inserted. New additions go to the end of the line, and elements are removed from the front. It creates a first-in first-out system. This interface is implemented by LinkedList, ArrayDeque, and PriorityQueue. LinkedList, of course, also implements the List interface and can also be used as one. But it also has the Queue methods. ArrayDeque implements the queue as an array. It also implements the Deque interface, giving it more flexibility.<ref>http://download.oracle.com/javase/6/docs/api/java/util/Queue.html</ref>
 
===PriorityQueue Class===
PriorityQueue implements Queue, but also alters it. Instead of elements being ordering by the order in which they are inserted, they are ordered by priority. The method used to determine priority is either the compareTo() method in the elements or a method given in the constructor.<ref>http://download.oracle.com/javase/6/docs/api/java/util/PriorityQueue.html</ref>
 
== See also ==