12:35 am - Monday March 27, 2017

The unmodifiableSortedMap() method is used to return an unmodifiable view of the specified sorted map. in ascending order

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 unmodifiableSortedMap() method is used to return an unmodifiable view of the specified sorted map. in ascending order

Example Program


import java.util.*;

public class UnmodifiableSortedmapcltn {
	public static void main(String[] args) {
		// create a sortedmap object
		SortedMap<String, String> map = new TreeMap<String, String>();
		// populate the map
		map.put("1", "abi");
		map.put("2", "babu");
		map.put("3", "cva");
		// initial value in the map
		System.out.println("Initial map value: " + map);
		// make the sortedmap unmodify
		SortedMap<String, String> stmap = Collections
				.unmodifiableSortedMap(map);
		// try to modify the map
		stmap.put("4", "don");

	}

}

 

Output:  Initial map value: {1=abi, 2=babu, 3=cva}

Exception in thread “main” java.lang.UnsupportedOperationException

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

at SecondTask.UnmodifiableSortedmapcltn.main(UnmodifiableSortedmapcltn.java:18)

 Explanation: The unmodifiableSortedMap() method is used to return an unmodifiable view of the specified sorted map. in ascending 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 sorted map.

 Throw: NA

 

 

BACK

 

Filed in: Z-A All Java Codes

Comments are closed.