Some of the new collections APIs have been
introduced in Java 6.0. These are:
- 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.
- 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
- 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.
- 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:
- 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.
- 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.
- ConcurrentSkipListSet:
ConcurrentSkipListSet is one of the class that implements
NavigableSet. It is used to return the closest matches of
elements.
- ConcurrentSkipListMap:
ConcurrentSkipListMap is the one of the class which implements
NaviagableMap. In NavigableSet, methods use to return values.
- 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.
- AbstractMap.SimpleImmutableEntry: This class is
similar toAbstractMap.SimpleEntry class however it has one
difference that it throws the exceptionUnsupportedOperationException when
we try to set a value whileAbstractMap.SimpleEntry doesn?t.
Updated Classes in Java 6.0
·
LinkedList
·
TreeSet
·
TreeMap
·
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.
0 comments:
Post a Comment