ConcurrentSkipListMap example to make map unmodifiable in java

ConcurrentSkipListMap - making map unmodifiable using Collections.unmodifiableMap in java

HashMap vs Hashtable vs LinkedHashMap vs TreeMap - Differences

Map hierarchy in java - Detailed - HashMap, Hashtable, ConcurrentHashMap, LinkedHashMap, TreeMap, ConcurrentSkipListMap, IdentityHashMap, WeakHashMap, EnumMap classes

import java.util.Collections;
import java.util.Map;
import java.util.concurrent.ConcurrentSkipListMap;
/** Copyright (c), AnkitMittal */
public class ConcurrentSkipListMapUnmodifiableExample {
   public static void main(String args[]){
          Map<Integer,String> concurrentSkipListMap=new ConcurrentSkipListMap<Integer,String>();
          concurrentSkipListMap.put(11, "ankit");
          concurrentSkipListMap.put(21, "mittal");
          concurrentSkipListMap.put(31, "javaMadeSoEasy");
          //getting unmodifiable ConcurrentSkipListMap
          Map<Integer,String> unmodifiableMap = Collections.unmodifiableMap(concurrentSkipListMap);
          * Now any attempt to modify map will throw java.lang.UnsupportedOperationException
Exception in thread "main" java.lang.UnsupportedOperationException
   at java.util.Collections$UnmodifiableMap.put(Unknown Source)
   at concurrentSkipListMap_unmodifiable.concurrentSkipListMapTest.main(


HashMap - Iterate on keys by obtaining keySet, Iterate on values by obtaining values, Iterate on entry by obtaining entrySet

HashMap - synchronizing map using Collections.synchronizedMap

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...
//start paginationJs //end paginationJs