Collections.unmodifiableSortedSet(SortedSet) in Java

Collections.unmodifiableSortedSet(SortedSet): This method is available in java.util.Collections class of Java.

Syntax:

<E> SortedSet<E> java.util.Collections.unmodifiableSortedSet(SortedSet<E> s)

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

Parameters: One parameter is required for this method.

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

Returns: an unmodifiable view of the specified sorted set.

Exceptions: NA

Approach

Java

import java.util.Collections;
import java.util.SortedSet;
import java.util.TreeSet;

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

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

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

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

    }
}

Output:

[C++, Hello, Java]


No comments:

Post a Comment