Java Collections unmodifiableSortedSet() MethodThe unmodifiableSortedSet() method of Java Collections class is used to get an unmodifiable view of the specified sorted set. SyntaxFollowing is the declaration of unmodifiableSortedSet() method: Parameter
ReturnsThe unmodifiableSortedSet() method returns an unmodifiable view of the specified Sorted Set. ExceptionsNA Example 1Test it NowOutput: Unmodifiable Sorted set is :[Facebook, Instagram, Twitter, Whatsapp] Unmodifiable Sorted set after modify is:[Facebook, Google, Instagram, Twitter, Whatsapp] Example 2Test it NowOutput: Original Set: [1, 7, 9] Unmodifiable Sorted Set: [1, 7, 9] Unmodifiable Sorted Set: [1, 7, 9, 10] Example 3Test it NowOutput: Original Set: [1, 4, 7] Exception in thread "main" java.lang.UnsupportedOperationException at java.base/java.util.Collections$UnmodifiableCollection.add(Collections.java:1056) at myPackage.CollectionsUnmodifiableSortedSetExample3.main(CollectionsUnmodifiableSortedSetExample3.java:9) 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