VOOZH about

URL: https://www.geeksforgeeks.org/java/java-collections-emptynavigablemap-method-with-examples/

⇱ Java Collections emptyNavigableMap() Method with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java Collections emptyNavigableMap() Method with Examples

Last Updated : 3 Jan, 2022

The Java Collections emptyNavigableMap() method is used to get a map with no elements. A Navigable map is a data structure that can hold elements with key-value pairs.

Syntax:

public static final <Key,Value> SortedMap<Key,Value> emptyNavigableMap() 

where,

  • key is the key element
  • value is the value element

Parameters: This method will take no parameters.

Return Type: It will return an empty Navigable map that is immutable.

Example 1:


Output
{}

Example 2: In this program, we will create an empty navigable map and add elements to the map. This will return an error.

Output:

Exception in thread "main" java.lang.UnsupportedOperationException
 at java.util.Collections$UnmodifiableMap.put(Collections.java:1459)
 at GFG.main(GFG.java:10)

Example 3:

Output:

Exception in thread "main" java.lang.UnsupportedOperationException
 at java.util.Collections$UnmodifiableMap.put(Collections.java:1459)
 at GFG.main(GFG.java:10)
Comment