Java Collections emptySortedSet() MethodLast Updated : 17 Mar 2025 The emptySortedSet() method of Java Collections class is used to get the sorted Set that has no elements. These empty Set are immutable in nature. SyntaxFollowing is the declaration of emptySortedSet() method: ParameterThis method does not accept any parameter. ReturnsThe emptySortedSet() method returns an empty sorted Set. ExceptionsNA Compatibility VersionJava 1.8 and above Example 1Output: Empty Sorted Set: [] Example 2Output: Created empty immutable Sorted Set: []Exception in thread "main" java.lang.UnsupportedOperationException at java.base/java.util.Collections$UnmodifiableCollection.add(Collections.java:1056) at myPackage.CollectionsEmptySortedSetExample2.main(CollectionsEmptySortedSetExample2.java:9) Example 3Output: Exception in thread "main" java.lang.UnsupportedOperationException at java.base/java.util.Collections$UnmodifiableCollection.add(Collections.java:1056) at myPackage.CollectionsEmptySortedSetExample3.main(CollectionsEmptySortedSetExample3.java:8) 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