Java Collections synchronizedNavigableSet() Method with Examples
The synchronizedNavigableSet() method in Java collections is used to get the thread-safe navigable set with the given navigable set.
Syntax:
public static <T> NavigableSet<T> synchronizedNavigableSet(NavigableSet<T> set)
Parameters:
- set is the input navigable set.
Return: It will return the synchronized navigable set from the given input (navigable set).
Exception: It will not raise any exception.
Example:
Java
import java.util.*;
public class GFG {
public static void main(String[] args)
{
NavigableSet<String> data = new TreeSet<>();
data.add( "sravan-it" );
data.add( "manoj-cse" );
data.add( "sai-cse" );
data.add( "vignesh-it" );
Set<String> final1
= Collections.synchronizedNavigableSet(data);
System.out.println(final1);
}
}
|
Output
[manoj-cse, sai-cse, sravan-it, vignesh-it]
Example 2:
Java
import java.util.*;
public class GFG {
public static void main(String[] args)
{
NavigableSet<Integer> data = new TreeSet<>();
data.add( 7058 );
data.add( 4511 );
data.add( 7859 );
data.add( 4532 );
Set<Integer> final1
= Collections.synchronizedNavigableSet(data);
System.out.println(final1);
}
}
|
Output
[4511, 4532, 7058, 7859]
Example 3:
Java
import java.util.*;
public class GFG {
public static void main(String[] args)
{
NavigableSet<Integer> data = new TreeSet<>();
data.add( 7058 );
data.add( 4511 );
data.add( 7859 );
data.add( 4532 );
Set<Integer> final1
= Collections.synchronizedNavigableSet(data);
final1.remove( 4511 );
System.out.println(final1);
}
}
|
Output
[4532, 7058, 7859]
Last Updated :
03 Jan, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...