2:19 am - Wednesday April 26, 2017

The unmodifiableMap() method is used to return an unmodifiable view of the specified map in descending order using unmodifiableMap(Map m)

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

BACK

 

       The unmodifiableMap() method is used to return an unmodifiable view of the specified map in descending order

Example Program

import java.util.*;

public class UnmodifiableMapclt {
	public static void main(String[] args) {
		// create Hashtable object
		Hashtable<String, String> table = new Hashtable<String, String>();
		// put value in the table
		table.put("1", "sivan");
		table.put("2", "vivek");
		// display the initial table contennt
		System.out.println("intial table: " + table);
		// make the unmodifiable map
		Map<String, String> m = Collections.unmodifiableMap(table);
		// try to modify the Map
		m.put("3", "sathi");

	}
}

Output:  

intial table: {2=vivek, 1=sivan}

Exception in thread “main” java.lang.UnsupportedOperationException

at java.util.Collections$UnmodifiableMap.put(Unknown Source)

at SecondTask.UnmodifiableMapclt.main(UnmodifiableMapclt.java:17)

Explanation: //The unmodifiableMap() method is used to return an unmodifiable view of the specified map in descending order

Parameter: m–This is the map for which an unmodifiable view is to be returned.

Return:   The method call returns an unmodifiable view of the specified map.

Throws: NA

 

BACK

Filed in: Z-A All Java Codes

Comments are closed.