Online Java Compiler By
JavaTpoint.com
import java.util.*; public class CollectionsUnmodifiableMapExample1 { public static void main(String[] args) { //Create object of hash map and Add values in the map HashMap
map = new HashMap
(); map.put("key1", "Java"); map.put("key2", "Android"); map.put("key3", "JavaScript"); System.out.println("Initial collection: "+map); //Create unmodifiable map Map
map2 = Collections.unmodifiableMap(map); System.out.println("Unmodifiable Map: " + map2); map.put("key4", "JavaTpoint"); System.out.println("Unmodifiable Map after adding: " + map2); } }
Output