Site icon JavaGoal

containsValue(Object value)

containsvalue(Object value): This method is used to check whether the specified Value exists in TreeMap or not. It returns type is boolean. If the given value exists TreeMap, then it returns true otherwise false in Java.

containsValue(Object value)

Where, Value is the  value which you want to check in TreeMap.
return type:  Its return type is boolean. It can return either true or false.

import java.util.TreeMap;
public class ExampleOfTreeMap 
{
	public static void main(String[] args) 
	{
		TreeMap<Integer, String> listOfNames = new TreeMap<Integer, String>();
		
		listOfNames.put(1, "JAVA");
		listOfNames.put(2, "GOAL");
		listOfNames.put(3, "RAVI");
		
		// Return, true because value JAVA is exist 
		System.out.println("Is Value JAVA is present in HashMap = "+listOfNames.containsValue("JAVA"));
		// Return, false because value Hello doesn't exist 
		System.out.println("Is Value Hello is present in HashMap = "+listOfNames.containsValue("Hello"));
		
	}
}

Output: Is Value JAVA is present in HashMap = true
Is Value Hello is present in HashMap = false

Exit mobile version