Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Create an unmodifiable map in Java

import java.util.*;
public class Demo {
	public static void main(String[] s) {
		Hashtable<String,String>hash = new Hashtable<String,String>();
		hash.put("key1", "value1");
		hash.put("key2", "value2");
		hash.put("key3", "value3");
		System.out.println("Initial collection: "+hash);
		Map map= Collections.unmodifiableMap(hash);
		// error will generate
		map.put("key3", "value3");
	}
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.