ConcurrentSkipListMap class extends the abstract class AbstractMap and is implement the ConcurrentNavigableMap interface. ConcurrentSkipListMap is a part of Java collection framework and is available in java.util package.
Java collection framework - ConcurrentSkipListMap
ConcurrentSkipListMap class extends the abstract class AbstractMap and is implement the ConcurrentNavigableMap interface. ConcurrentSkipListMap is a part of Java collection framework and is available in java.util package. The elements of this map are arranged in natural order according to their keys or by a comparator put up at the time of creation. This class doesn't allow 'null' key's or values because the return of few 'null' values can't be reliably differentiated from the absence of elements.
Syntax
public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V> implements ConcurrentNavigableMap<K,V>
Constructor of ConcurrentSkipListMap
This class provides constructor for constructing new map according to requirement :
ConcurrentSkipListMap() : It creates a new vacate map into which mappings are sorted according to the keys natural order.
ConcurrentSkipListMap(Comparator<? super K> comparator) : It creates a new vacate map into which the mappings are sorted according to the defined comparator.
ConcurrentSkipListMap(Map<? extends K,? extends V> m) : It creates a new map that contains the same mappings of a given map into which mappings are sorted according to the keys natural order.
ConcurrentSkipListMap(SortedMap<K,? extends V> m) : It creates a new map that contains the same mappings and follows the order like the defined sorted map.
Methods of ConcurrentSkipListMap
This class provides various methods some of them are :
- put()
- ceilingKey()
- floorKey()
- lastKey()
- lowerKey(K key)
syntax : public V put(K key,V value)
syntax : public K ceilingKey(K key)
syntax : public K floorKey(K key)
syntax : public K lastKey()
syntax : public K lowerKey(K key)
Example
package devmanuals.com; import java.util.Map; import java.util.Set; import java.util.SortedMap; import java.util.concurrent.ConcurrentSkipListMap; public class ConcurrentSkipListMapDemo { public static void main(String[] args) { ConcurrentSkipListMap clm=new ConcurrentSkipListMap(); clm.put(1,"Sunday"); clm.put(2,"Monday"); clm.put(3,"Tuesday"); clm.put(4,"Wednesday"); clm.put(5,"Thursday"); clm.put(6,"Friday"); clm.put(7,"Saturday"); System.out.println("Mappings ="); System.out.println(clm); Map.Entry me = clm.lowerEntry(5); System.out.println(me); System.out.println("Key " + me.getKey()); System.out.println("Value "+me.getValue()); SortedMap sm = clm.tailMap(3); Set s = sm.keySet(); System.out.println("Tail elements are"); System.out.println(clm.tailMap(4)); } }
Output :
Mappings = {1=Sunday, 2=Monday, 3=Tuesday, 4=Wednesday, 5=Thursday, 6=Friday, 7=Saturday} 4=Wednesday Key =4 Value =Wednesday Tail elements are {4=Wednesday, 5=Thursday, 6=Friday, 7=Saturday} |
[ 0 ] Comments