VOOZH about

URL: https://www.geeksforgeeks.org/java/treemap-containsvalue-method-in-java-with-examples/

⇱ TreeMap containsValue() Method in Java With Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

TreeMap containsValue() Method in Java With Examples

Last Updated : 11 Jul, 2025

In Java, containsValue() method of the TreeMap class is used to check whether a particular value is being mapped by any key in the TreeMap. It takes the value as a parameter and returns True if that value is mapped by any of the keys in the map.

--> java.util Package 
 --> TreeMap class
 --> containsValue() Method 

Syntax: 

Tree_Map.containsValue(Object Value)

Parameters: The value of Object type and refers to the value whose mapping is supposed to be checked by any key inside the map. ( Only one parameter)

Return Type: A boolean value, true if the mapping of the value is detected else false.

Note: In java, while returning boolean values are returned as true false only not as 0 and 1 as it is not allowed so do will throw error at compilation.

Example 1: Mapping String Values to Integer Keys. 


Output
Initial Mappings are: {10=Geeks, 15=4, 20=Geeks, 25=Welcomes, 30=You}
Is the value 'Geeks' present? true
Is the value 'World' present? false

Example 2: Mapping Integer Values to String Keys. 

Output: 

👁 Image

Note: Similarly the same operation can be performed with any type of Mappings with variation and combination of different data types.

Comment