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

Comments

Recent Post

Recent Posts Widget

Popular posts from this blog

Capture image from webcam java code, examples

Use of req.query, req.params and req.body in NODE JS

How to capture finger prints in java