Infolinks In Text Ads

Nov 23, 2010

SortedMap Interface

SortedMap Interface -
    SortedMap is an interface which extends Map Interface. SortedMap is important because it maintain the natural ascending order on its key. You can maintain another ordering through the Comparator interface on its creation time of SortedMap.
    It also has some extra method except Map Interface. You can find subMap, headMap, tailMap through the SortedMap Interface.

Now I am explaining the methods of SortedMap Interface.

Comparator<? super K> comparator() -
    This method gives the object of comparator if any ordering is maintaining on creation time. If Map has by default natural ascending order then it returns null.

SortedMap<K, V> subMap(K fromKey, K toKey) -
    This method is used to give the view of Map which is in range of fromKey and toKey. It will return empty map if range will not exactly match.

SortedMap<K, V> headMap(K toKey) -
    This method is used to give the view of map which belongs after the given key.

SortedMap<K, V> tailMap(K fromKey) -
    This method is used to give the view of map which belongs before the given key.

K firstKey() -
    This method is used to return the first element from the map.

K lastKey() - 
    This method is used to return the first element from the map.

There are some classes which implements SortedMap Interface
1.ConcurrentSkipListMap
2.TreeMap

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...