VOOZH about

URL: https://www.geeksforgeeks.org/java/java-collections-synchronizednavigablemap%e2%80%8b-method-with-examples/

⇱ Java Collections synchronizedNavigableMap​() Method with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java Collections synchronizedNavigableMap​() Method with Examples

Last Updated : 28 Dec, 2021

NavigableMap is used for convenient navigation methods like lowerKey, floorKey, ceilingKey, and higherKey, along with this popular navigation method. It will take key-value pair as input

We can create a navigable map by using the following syntax:

NavigableMap<key_datatype, value_datatype> data= new TreeMap<key_datatype, value_datatype>(); 

where

  • data is the input data.
  • key_datatype refers to the key type element.
  • value_datatype refers to the value type element.

synchronizedNavigableMap() Method will return the synchronized, which is a thread-safe navigable map backed by the specified navigable map.

Syntax:

public static <Key,Value> NavigableMap<K,V> synchronizedNavigableMap(NavigableMap<Key,Value> data)

where data is the navigable map which will be wrapped into a synchronized navigable map.

Return Type: The synchronizedNavigableMap() method returns a synchronized view of the specified Navigable Map.

Example 1: Create a synchronized navigable map using string elements


Output
{1=java, 2=python, 3=php, 4=html/js}

Example 2:


Output
{1=34, 2=45, 3=74, 4=41, 5=4, 6=40}
Comment