Collections.unmodifiableNavigableMap(NavigableMap) in Java

Collections.unmodifiableNavigableMap(NavigableMap): This method is available in java.util.Collections class of Java.

Syntax:

<E1, E2> NavigableMap<E1, E2> java.util.Collections.unmodifiableNavigableMap(NavigableMap<E1, ? extends E2> m)

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

Parameters: One parameter is required for this method.

m: the navigable map for which an unmodifiable view is to be returned

Returns: an unmodifiable view of the specified navigable map.

Exceptions: NA

Approach

Java

import java.util.Collections;
import java.util.NavigableMap;
import java.util.TreeMap;

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

        NavigableMap<String, Integer> map = new
TreeMap<String, Integer>();

        map.put("Hello", 1);
        map.put("Java", 2);
        map.put("C++", 3);

        System.out.println(Collections.unmodifiableNavigableMap(map));

    }
}

Output:

{C++=3, Hello=1, Java=2}


No comments:

Post a Comment