Javatpoint Logo
Javatpoint Logo

Java Collections unmodifiableNavigableSet() Method

The unmodifiableNavigableSet() method of Java Collections class is used to get an unmodifiable view of the specified navigable set.

Syntax

Following is the declaration of unmodifiableNavigableSet() method:

Parameter

Parameter Description Required/Optional
s It is the navigable set for which an unmodifiable view is to be returned. Required

Returns

The unmodifiableNavigableSet() method returns an unmodifiable view of the specified navigable set.

Exceptions

NA

Compatibility Version

Java 1.8 and above

Example 1

Test it Now

Output:

Initial Set: [1, 2, 3, 4, 5]
Unmodifiable Navigable Set: [1, 2, 3, 4, 5]
Unmodifiable Navigable Set: [1, 2, 3, 4, 5, 15]

Example 2

Test it Now

Output:

Initial Set: [Facebook, Google, Instagram]
Unmodifiable Navigable Set: [Facebook, Google, Instagram]
Unmodifiable Navigable Set: [Facebook, Google, Instagram, Twitter]

Example 3

Test it Now

Output:

Original Set: [11, 13, 17]
Exception in thread "main" java.lang.UnsupportedOperationException
	at java.base/java.util.Collections$UnmodifiableCollection.add(Collections.java:1056)
	at myPackage.CollectionsUnmodifiableNavigableSetExample3.main(CollectionsUnmodifiableNavigableSetExample3.java:9)






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA