Home » Java Collections synchronizedNavigableSet() Method with Examples

Java Collections synchronizedNavigableSet() Method with Examples

by Online Tutorials Library

Java Collections synchronizedNavigableSet() Method

The synchronizedNavigableSet() method of Java Collections class is used to get a synchronized (thread-safe) navigable set backed by the specified navigable set.

Syntax

Following is the declaration of synchronizedNavigableSet() method:

Parameter

Parameter Description Required/Optional
s It is the navigable set which will be wrapped in a synchronized navigable set. Required

Returns

The synchronizedNavigableSet() method returns a synchronized view of the specified Navigable Set.

Exceptions

NA

Compatibility Version

Java 1.8 and above

Example 1

Test it Now

Output:

Synchronized navigable set is :[Facebook, Google, Instagram, TutorAspire ]  

Example 2

Test it Now

Output:

Set before Synchronized navigable set: [1001, 1002, 1003, 1004, 1005]  Synchronized navigable set after remove(1004):[1001, 1002, 1003, 1005]  

Example 3

Test it Now

Output:

1000  

Example 4

Test it Now

Output:

Set before Synchronized navigable set: [1001, 1002, 1003, 1004, 1005]  Set after Synchronized navigable set-  1001  1002  1003  1004  1005  

You may also like