Home » Java Collections emptySortedMap() Method with Examples

Java Collections emptySortedMap() Method with Examples

by Online Tutorials Library

Java Collections emptySortedMap() Method

The emptySortedMap() method of Java Collections class returns an empty sorted map which is immutable.

Syntax

Following is the declaration of emptySortedMap() method:

Parameter

This method does not accept any parameter.

Returns

The emptySortedMap() method returns an empty immutable Sorted Map.

Exceptions

NA

Compatibility Version

Java 1.8 and above

Example 1

Test it Now

Output:

Created Empty Sorted Map: {}  

Example 2

Test it Now

Output:

Created Empty Sorted Map: {}  Exception in thread "main" java.lang.UnsupportedOperationException  at java.base/java.util.Collections$UnmodifiableMap.put(Collections.java:1453)  at myPackage.CollectionsEmptySortedMapExample2.main(CollectionsEmptySortedMapExample2.java:9)  

Example 3

Test it Now

Output:

Exception in thread "main" java.lang.UnsupportedOperationException  at java.base/java.util.Collections$UnmodifiableMap.put(Collections.java:1453)  at myPackage.CollectionsEmptySortedMapExample3.main(CollectionsEmptySortedMapExample3.java:8)  

You may also like