Collections.unmodifiableNavigableSet(NavigableSet) in Java

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

Syntax:

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

This method takes one argument. This method returns an unmodifiable view of the specified navigable set.

Parameters: One parameter is required for this method.

s: the navigable set for which an unmodifiable view is to be returned.

Returns: an unmodifiable view of the specified navigable set.

Exceptions: NA

Approach

Java

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

public class CollectionsunmodifiableNavigableSet {
    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.unmodifiableNavigableSet(set));

    }
}

Output:

[C++, Hello, Java]


No comments:

Post a Comment