Collections.synchronizedNavigableSet(NavigableSet) in Java

Collections.synchronizedNavigableSet(NavigableSet): This method is available in java.util.Collections class of Java.

Syntax:

<E> NavigableSet<E> java.util.Collections.synchronizedNavigableSet(NavigableSet<E> s)

This method takes one argument. This method returns a synchronized (thread-safe) navigable set backed by the specified navigable set.

Parameters: One parameter is required for this method.

s: the navigable set to be "wrapped" in a synchronized navigable set.

Returns: a synchronized view of the specified navigable set.

Exceptions: NA

Approach

Java

import java.util.Collections;
import java.util.NavigableSet;
import java.util.TreeSet;

public class CollectionssynchronizedNavigableSet {
    public static void main(String[] args) {

        NavigableSet<String> set = new TreeSet<String>();

        set.add("Hello");
        set.add("Java");
        set.add("C++");

        System.out.println(Collections.synchronizedNavigableSet(set));

    }
}

Output:

[C++, Hello, Java]


No comments:

Post a Comment