1import java.util.TreeMap;
2public class TreeMapContainsValueMethodExample
3{
4 public static void main(String[] args)
5 {
6 TreeMap<Integer, String> tm = new TreeMap<Integer, String>();
7 // Map string values to integer keys
8 tm.put(16, "indigo");
9 tm.put(12, "red");
10 tm.put(14, "indigo");
11 tm.put(18, "orange");
12 tm.put(20, "violet");
13 System.out.println("TreeMap before using containsValue() method: " + tm);
14 // checking for Value 'indigo'
15 System.out.println("Does value 'indigo' present? " + tm.containsValue("indigo"));
16 // checking for Value 'blue'
17 System.out.println("Does value 'blue' present? " + tm.containsValue("blue"));
18 }
19}
1map Integer values to String keys
2import java.util.TreeMap;
3public class TreeMapContainsValueMethodExample
4{
5 public static void main(String[] args)
6 {
7 TreeMap<String, Integer> tm = new TreeMap<String, Integer>();
8 // Map integer values to string keys
9 tm.put("indigo", 16);
10 tm.put("red", 12);
11 tm.put("indigo", 14);
12 tm.put("orange", 18);
13 tm.put("violet", 20);
14 System.out.println("TreeMap before using containsValue() method: " + tm);
15 // Checking for the Value '12'
16 System.out.println("Does value '12' present? " + tm.containsValue(12));
17 // Checking for the Value '14'
18 System.out.println("Does value '14' present? " + tm.containsValue(14));
19 // Checking for the Value '20'
20 System.out.println("Does value '20' present? " + tm.containsValue(20));
21 }
22}