public
boolean containsValue(Object value)
Returns
true if this map maps one or more keys to the specified value.
import java.util.*; class TreeMapContainsValue{ public static void main(String args[]){ TreeMap<Integer, String> myMap1; myMap1 = new TreeMap<> (); /* Add data to the myMap1 */ myMap1.put(1, "First"); myMap1.put(2, "Second"); myMap1.put(3, "Third"); myMap1.put(4, "Fourth"); System.out.println("Data in myMap1 is"); System.out.println(myMap1); System.out.print("\nIs myMap1 contains Value First "); System.out.println(myMap1.containsValue("First")); System.out.print("Is myMap1 contains Value Last "); System.out.println(myMap1.containsValue("Last")); } }
Output
Data in myMap1 is {1=First, 2=Second, 3=Third, 4=Fourth} Is myMap1 contains Value First true Is myMap1 contains Value Last false
No comments:
Post a Comment