Java Collections checkedSortedMap() MethodLast Updated : 17 Mar 2025 The 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 1Output:
Type safe view of the Sorted Map is: {ABCD=1200, Hindi100=500, JavaTpoint=1100, SSSIT=1300}
Example 2Output:
Type safe view of the Sorted Map is: {500=Hindi100, 900=ABCD, 1100=JavaTpoint, 1800=SSSIT}
Example 3Output:
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 request you to subscribe our newsletter for upcoming updates.

We deliver comprehensive tutorials, interview question-answers, MCQs, study materials on leading programming languages and web technologies like Data Science, MEAN/MERN full stack development, Python, Java, C++, C, HTML, React, Angular, PHP and much more to support your learning and career growth.
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India