View RSS Feed

My Java Tips

More on Collection FrameWork

Rate this Entry
by , 11-08-2011 at 06:54 PM (1146 Views)
Here we assume that programmer is well aware about the basic concepts of Collections Framework. For more information about basics on Collection Framework click here.
Now have a look on the classes that implement the " Collection " and " Map " interface.

As the collection interfaces have a few methods that can be easily implemented from fundamental methods where as abstract classes in the collection framework supply some of these routine implementations.


It is important to have a look on these classes. An implementation of a collection class, and then an extension of one of the above abstract classes can ease the task to achieve some additional features to the existing collection framework to a considerable extend.

The JDK library supplies concrete classes of these abstract classes for different purposes:


Important points about these classes are discussed below.

LinkedList, an implementation of " List " interface is useful for memory utilizations as memory occupied by LinkedList is not in contiguous location.
ArrayList, an implementation of " List " interface simply allocates memory at contiguous location. Hence if you need to work on index based traversal use ArrayList.
HashSet, an implementation of " Set " interface backed by a " HashTable ". Actually a " HashMap " instance It does not guarantee that the Order of elements will be maintianed for every retrieval. This class permits the null element.
TreeSet class implements the " Set " interface, this class ensures that the sorted set will be in ascending element order, sorted according to the natural order of the elements ( By use of " Comparable " or by the comparator provided at set creation time.
PriorityQueue: This queue orders elements according to an order specified at construction time, which is specified either according to their natural order (see Comparable Interface), or according to a Comparator, A priority queue does not permit null elements. A priority queue relies on natural ordering also does not permit insertion of non- comparable objects( doing so may result in ClassCastException).
HashMap: It is a " Hashtable " based implementation of the " Map " interface. This implementation provides all of the optional map operations, and permits null key- value pair. The HashMap class is roughly equivalent to Hashtable but it is not synchronized and permits nulls. This class makes no guarantees of the order of the elements.
TreeMap: It is Red-Black tree based implementation of the " SortedMap " interface. This class guarantees that the map will be in ascending key order, sorted according to the natural order for the key's class (see Comparable), or by the comparator provided at creation time, depending on constructor used.

Submit "More on Collection FrameWork" to Facebook Submit "More on Collection FrameWork" to Digg Submit "More on Collection FrameWork" to Submit "More on Collection FrameWork" to StumbleUpon Submit "More on Collection FrameWork" to Google

Tags: None Add / Edit Tags
Collections Framework , Java SE