TreeMap containsValue() method in java code example
Example 1: TreeMap containsValue() method in java
map Integer values to String keys
import java.util.TreeMap;
public class TreeMapContainsValueMethodExample
{
public static void main(String[] args)
{
TreeMap<String, Integer> tm = new TreeMap<String, Integer>();
tm.put("indigo", 16);
tm.put("red", 12);
tm.put("indigo", 14);
tm.put("orange", 18);
tm.put("violet", 20);
System.out.println("TreeMap before using containsValue() method: " + tm);
System.out.println("Does value '12' present? " + tm.containsValue(12));
System.out.println("Does value '14' present? " + tm.containsValue(14));
System.out.println("Does value '20' present? " + tm.containsValue(20));
}
}
Example 2: TreeMap containsValue() method in java
import java.util.TreeMap;
public class TreeMapContainsValueMethodExample
{
public static void main(String[] args)
{
TreeMap<Integer, String> tm = new TreeMap<Integer, String>();
tm.put(16, "indigo");
tm.put(12, "red");
tm.put(14, "indigo");
tm.put(18, "orange");
tm.put(20, "violet");
System.out.println("TreeMap before using containsValue() method: " + tm);
System.out.println("Does value 'indigo' present? " + tm.containsValue("indigo"));
System.out.println("Does value 'blue' present? " + tm.containsValue("blue"));
}
}