Java Collection Framework - ConcurrentNavigableMap<k,v> Interface

Java Collection Framework - ConcurrentNavigableMap Interface


Posted in : Core Java Posted on : March 17, 2011 at 11:57 AM Comments : [ 0 ]

In java, ConcurrentNavigableMap is the interface which inherited the NavigableMap, and ConcurrentMap, in other word we can say this interface is the sub-interface of these two NavigableMap, and ConcurrentMap interfaces and also contains the methods with few changes.� 

Java Collection Framework - ConcurrentNavigableMap<k,v> Interface

In java, ConcurrentNavigableMap is the interface which inherited the NavigableMap<k,v>, and ConcurrentMap<k,v>, in other word we can say this interface is the sub-interface of  these two NavigableMap<k,v>, and ConcurrentMap<k,v> interfaces and also contains the methods with few changes. 

Parameter description

k : It is the key's type held by the map.

v : The type of value associated by key.

The list of methods supported by ConcurrentNavigableMap interface are given below :

  • descendingKeySet() : This method gives back the NavigableSet view of keys in inverse order.
  • descendingMap() : This method gives back the view of mappings in inverse order.
  • headMap(K toKey) : This method returns the view part of the underlying map whose keys are stringently less than the 'toKey'.
  • headMap(K toKey, boolean inclusive) : This map returns the view part of the underlying map in which the keys are smaller than or equal (if inclusive=true) to the 'toKey'.
  • keySet() : It returns a view of set of keys of NavigableSet contained by the underlying map.
  • navigableKeySet() : In this method NavigableSet of keys contained by the underlying map is returned.
  • subMap(K fromKey, K toKey) : This method returns a view portion between the keys range from 'fromKey', 'inclusive', to 'toKey', 'exclusive'. 
  • subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive) : It gives back a view portion between the keys range from 'fromKey' to 'toKey' of the underlying map.
  • tailMap(K fromKey) : This method gives back the view part of the underlying map, in which the keys are existed than the larger or equal to the 'fromKey'.
  • tailMap(K fromKey, boolean inclusive) : This method gives back the view part of the underlying map in which the keys are larger than or equal (if inclusive=true) to the 'fromKey'.

Here is the simple example for demonstration of the ConcurrentNavigableMap interface :-

Example :

package devmanuals.com;
import java.util.NavigableSet;
import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
public class ConNavMapDemo {
  public static void main (String args[]){
    ConcurrentNavigableMap cnm =
                        new ConcurrentSkipListMap();
    cnm.put(1, "Rose");
    cnm.put(2, "India");
    cnm.put(3, "Technology");
    cnm.put(4, "Dev");
    cnm.put(5, "Manuals");
    cnm.put(6, ".com");
    System.out.println("Mapping = "+cnm);
    NavigableSet s = cnm.keySet();
    System.out.println("Set of keys = "+s);
    System.out.println("Size of map = "+cnm.size());
  }
}

Output :

Mapping = {1=Rose, 2=India, 3=Technology, 4=Dev, 5=Manuals, 6=.com}

Set of keys = [1, 2, 3, 4, 5, 6}.

Size of map = 6

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics