Collections.synchronizedNavigableMap(NavigableMap) in Java

Collections.synchronizedNavigableMap(NavigableMap): This method is avaiable in java.util.Collections class of Java.

Syntax:

<E1, E2> NavigableMap<E1, E2> java.util.Collections.synchronizedNavigableMap(NavigableMap<E1, E2> m)

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

Parameters: One parameter is required for this method.

m: the navigable map to be "wrapped" in a synchronized navigable map.

Returns: a synchronized view of the specified navigable map.

Exceptions: NA

Approach

Java

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

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

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

        map.put("Hello", 12);
        map.put("Java", 23);
        map.put("C++", 25);

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

    }
}

Output:

{C++=25, Hello=12, Java=23}


No comments:

Post a Comment