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

Make a Hashtable read-only in Java

import java.util.Collections;
import java.util.Hashtable;
import java.util.Map;
public class Demo {
	public static void main(String[] s) {
		Hashtable<String, String>hash = new Hashtable<String, String>();
		hash.put("1", "A");
		hash.put("2", "B");
		hash.put("3", "C");
		hash.put("4", "D");
		hash.put("5", "E");
		hash.put("6", "F");
		hash.put("7", "G");
		hash.put("8", "H");
		hash.put("9", "I");
		hash.put("10", "J");
		System.out.println("Hashtable = " + hash);
		Map<String, String>m = Collections.unmodifiableMap(hash);
		System.out.println("Hashtable is now read-only!");
	}
}

Advertisements
Loading...

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