Java Collections checkedSortedMap() MethodThe checkedSortedMap() is an inbuilt method of Java Collections class. This method is used to get a dynamically typesafe view of the specified sorted map. SyntaxFollowing is the declaration of checkedSortedMap() method: Parameter
ReturnsThe checkedSortedMap() method returns a dynamically typesafe view of the specified Sorted Map. ExceptionsClassCastException Compatibility VersionJava 1.5 and above Example 1Test it NowOutput: Type safe view of the Sorted Map is: {ABCD=1200, Hindi100=500, JavaTpoint=1100, SSSIT=1300} Example 2Test it NowOutput: Type safe view of the Sorted Map is: {500=Hindi100, 900=ABCD, 1100=JavaTpoint, 1800=SSSIT} Example 3Test it NowOutput: Map content: {500=Hindi100, 900=ABCD, 1100=JavaTpoint, 1800=SSSIT} Exception in thread "main" java.lang.ClassCastException: Attempt to insert class java.lang.Integer value into map with value type class java.lang.String at java.base/java.util.Collections$CheckedMap.typeCheck(Collections.java:3578) at java.base/java.util.Collections$CheckedMap.put(Collections.java:3621) at myPackage.CollectionCheckedSortedMapExample3.main(CollectionCheckedSortedMapExample3.java:15) Next TopicJava Collections Class |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India