Wednesday, 12 October 2016

What is ConcurrentNavigableMap In Java ?

Blog Author - Pushkar Khosla,
Software Developer by Profession with 3.0 Yrs of Experience , through this blog i'am sharing my industrial Java Knowledge to entire world. For any question or query any one can comment below or mail me at pushkar.itsitm52@gmail.com.

This blog is all about to learn Core Java ,Interview Programs and Coding tricks to polish your Java Knowledge. If you like the content of this blog please share this with your friends.

Previously we have discussed about
what Is Navigablemap In Java ?
Here we learn what is ConcurrentNavigableMap in java.But before starting this you must know What is Map Interface in Java ?
Interface ConcurrentNavigableMap<K,V>

Type Parameters:
K - the type of keys maintained by this map
V - the type of mapped values

All Superinterfaces:
ConcurrentMap<K,V>, Map<K,V>, NavigableMap<K,V>, SortedMap<K,V>

All Known Implementing Classes:
ConcurrentSkipListMap

Declaration of ConcurrentNavigableMap:
public interface ConcurrentNavigableMap<K,V>
extends ConcurrentMap<K,V>, NavigableMap<K,V>

A ConcurrentMap supporting NavigableMap operations, and recursively so for its navigable sub-maps.
The "submaps" are the maps returned by various methods like headMap(), subMap() and tailMap().


This interface is a member of the Java Collections Framework.

Method Summary of ConcurrentNavigableMap:

Modifier and Type
Method Name
Description
NavigableSet<K>
descendingKeySet()
Returns a reverse order NavigableSet view of the keys contained in this map.
ConcurrentNavigableMap<K,V>
descendingMap()
Returns a reverse order view of the mappings contained in this map.
ConcurrentNavigableMap<K,V>
headMap(K toKey)
Returns a view of the portion of this map whose keys are strictly less than toKey.
ConcurrentNavigableMap<K,V>
headMap(K toKey, boolean inclusive)
Returns a view of the portion of this map whose keys are less than (or equal to, if inclusive is true) toKey.
NavigableSet<K>
keySet()
Returns a NavigableSet view of the keys contained in this map.
NavigableSet<K>
navigableKeySet()
Returns a NavigableSet view of the keys contained in this map.
ConcurrentNavigableMap<K,V>
subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive)
Returns a view of the portion of this map whose keys range from fromKey to toKey.
ConcurrentNavigableMap<K,V>
subMap(K fromKey, K toKey)
Returns a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive.
ConcurrentNavigableMap<K,V>               
tailMap(K fromKey)
Returns a view of the portion of this map whose keys are greater than or equal to fromKey.
ConcurrentNavigableMap<K,V>               
tailMap(K fromKey, boolean inclusive)
Returns a view of the portion of this map whose keys are greater than (or equal to, if inclusive is true) fromKey.

Example of ConcurrentNavigableMap :

import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;

public class ConcurrentNavigableMapExample {
public static void main(String[] args) {
ConcurrentNavigableMap<String,String> map = new ConcurrentSkipListMap<String,String>();
map.put("1", "Apple");
map.put("2", "Banana");
map.put("3", "Orange");
System.out.println("ConcurrentNavigableMap Elements : "+map);
ConcurrentNavigableMap<String,String> head = map.headMap("2");
System.out.println("\nHeadMap() Method will print the keys less than 2 : "+head);
ConcurrentNavigableMap<String,String> tail = map.tailMap("2");
System.out.println("\nTailMap() Method will print the keys greater than 2 : "+tail);

ConcurrentNavigableMap<String,String> sub = map.subMap("2","3");
System.out.println("\nSubMap() Method will print the keys between keys 2 and 3 : "+sub);
}
}

Program Output :

ConcurrentNavigableMap Elements : {1=Apple, 2=Banana, 3=Orange}

HeadMap() Method will print the keys less than 2 : {1=Apple}

TailMap() Method will print the keys greater than 2 : {2=Banana, 3=Orange}

SubMap() Method will print the keys between keys 2 and 3 : {2=Banana}



No comments:

Post a Comment