Friday, February 13, 2026
HomeLanguagesJavaJava Collections synchronizedNavigableSet() Method with Examples

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




// Java program to add elements
// to the Navigable set and convert
// them into the synchronized 
// navigable set with string data
import java.util.*;
  
public class GFG {
    // main method
    public static void main(String[] args)
    {
        // create an navigable tree set
        NavigableSet<String> data = new TreeSet<>();
  
        // add elements into the set
        data.add("sravan-it");
        data.add("manoj-cse");
        data.add("sai-cse");
        data.add("vignesh-it");
  
        // get the synchronized navigable 
        // set from the above set
        Set<String> final1
            = Collections.synchronizedNavigableSet(data);
  
        // display
        System.out.println(final1);
    }
}


Output

[manoj-cse, sai-cse, sravan-it, vignesh-it]

Example 2:

Java




// Java program to add elements to the Navigable
// set and convert into the synchronized 
// navigable set with integer data
import java.util.*;
  
public class GFG {
    // main method
    public static void main(String[] args)
    {
        // create an navigable tree set
        NavigableSet<Integer> data = new TreeSet<>();
  
        // add elements into the set
        data.add(7058);
        data.add(4511);
        data.add(7859);
        data.add(4532);
  
        // get the synchronized navigable 
        // set from the above set
        Set<Integer> final1
            = Collections.synchronizedNavigableSet(data);
  
        // display
        System.out.println(final1);
    }
}


Output

[4511, 4532, 7058, 7859]

Example 3: 

Java




// Java program to remove an item
// from the synchronized navigable
// set
import java.util.*;
  
public class GFG {
    // main method
    public static void main(String[] args)
    {
        // create an navigable tree set
        NavigableSet<Integer> data = new TreeSet<>();
  
        // add elements into the set
        data.add(7058);
        data.add(4511);
        data.add(7859);
        data.add(4532);
  
        // get the synchronized navigable 
        // set from the above set
        Set<Integer> final1
            = Collections.synchronizedNavigableSet(data);
  
        // remove 4511 element
        final1.remove(4511);
        // display
        System.out.println(final1);
    }
}


Output

[4532, 7058, 7859]
RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32499 POSTS0 COMMENTS
Milvus
128 POSTS0 COMMENTS
Nango Kala
6878 POSTS0 COMMENTS
Nicole Veronica
11999 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12092 POSTS0 COMMENTS
Shaida Kate Naidoo
7010 POSTS0 COMMENTS
Ted Musemwa
7248 POSTS0 COMMENTS
Thapelo Manthata
6961 POSTS0 COMMENTS
Umr Jansen
6953 POSTS0 COMMENTS