Home Java Jdk6 Java 6.0 Collection Framework

Related Tutorials


 
 

Share on Google+Share on Google+

Java 6.0 Collection Framework

Advertisement
Here you will learn some of the new collections APIs have been introduced in Java 6.0.

Java 6.0 Collection Framework

     

 Some of the new collections APIs have been introduced in Java 6.0. These are:

  1. Deque: It is used to represent Double ended queue. With the help of this collection we can add or remove elements at both the ends. Deque implementation can be used as Stack (Last in first out) or Queue (First in First Out). There are two methods in Deque, which are used for insertion, retrieval and removal of elements. One returns status or special value for each operation and the other will throw exception if it fails in an operation.
  1. BlockingDeque: It is similar to Deque but with added functionality. When we try to insert an element in a BlockingDeque and if the BlockingDeque is already full then the element can wait till the space becomes available to insert an element. There are four methods available for BlockingDeque.
    • Methods throws exception
    • Methods that times out (Waits for a given time for space to available)
    • Methods that blocks (Waits indefinitely for space to available)
    • Methods returns special value
  1. NavigableSet: It is used to return the closest matches of elements. For instance if we want retrieve the element, which is immediately greater than, or lower than element 20 or if we want to retrieve all elements greater than or lower than 35 from sorted set elements [10,20,35,5] we can use NavigableSet methods that becomes just a method call. ConcurrentSkipListSet is one of the class that implements NavigableSet.
  1. NavigableMap: In NavigableSet, methods use to return values, but in NaviagableMap methods used to return the key,value pair. ConcurrentSkipListMap is the one of the class which implements NaviagableMap

Some of the new Classes are: 

  1. ArrayDeque: ArrayDeque is a class that implements Deque. If used as a stack or linked list, it performs much faster than before. It is neither thread safe nor has capacity restrictions.
  1. LinkedBlockingDeque: It implements BlockingDeque. Maximum capacity can be specified by using BlockingDeque interface. However the maximum capacity will be Integer.MAX_VALUE if not specified.
  1. ConcurrentSkipListSet: ConcurrentSkipListSet is one of the class that implements NavigableSet. It is used to return the closest matches of elements.
  1. ConcurrentSkipListMap: ConcurrentSkipListMap is the one of the class which implements NaviagableMap. In NavigableSet, methods use to return values.
  1. AbstractMap.SimpleEntry: The key value pair of one single entry in a Map is held by the instance of this class. Moreover it is a static nested class nested inside abstractMap class.
     
  2. AbstractMap.SimpleImmutableEntry: This class is similar to AbstractMap.SimpleEntry class however it has one difference that it throws the exception UnsupportedOperationException when we try to set a value while AbstractMap.SimpleEntry doesn?t.

Updated Classes in Java 6.0

  1.  LinkedList
     

  2. TreeSet
     

  3. TreeMap
     

  4. Collections

Modified classes  

To implement the new interfaces we modify some classes like TreeSet is modified to implement NavigableSet, LinkedList is modified to implement Deque, TreeMap is modified to implement NavigableMap etc. Some of the new methods like newSetFromMap and asLifoQueue have been added to Collections 2.

 Hence the bi- directional traversal has become easier with java6.0 collections. We can even retrieve elements as desired.

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 22, 2007

Related Tutorials

Discuss: Java 6.0 Collection Framework   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
balu
June 21, 2012
Prog in LinkedHashMap

There are two LinkedHashMap objects are there and we store values to these two objects ,and get all keys from these objects and store in List For better understanding Map a=new LinkedHashMap(); a.put("1","one"); a.put("3","three"); Map b=new LinkedHashMap(); a.put("2","two"); a.put("4","four"); I want OutPut As: 1 2 3 4
DMCA.com