TreeMap boolean containsValue(Object value) Method Example Program


Returns true if this map maps one or more keys to the specified value. More formally, returns true if and only if this map contains at least one mapping to a value v such that (value==null ? v==null : value.equals(v)). This operation will probably require time linear in the map size for most implementations.

Program

package com.candidjava;

import java.util.TreeMap;
import java.util.NavigableMap;

/**
 * @author: Hari Haran
 * @discription: The containsValue(Object value) method is used to return true
 *               if this map, maps one or more keys to the specified value.
 */

public class TreeMapContainsValue {
	public static void main(String[] args) {
		NavigableMap<Integer, String> tm = new TreeMap<Integer, String>();

		tm.put(1, "Anand");
		tm.put(2, "Hari Haran");
		tm.put(8, "Kamal");
		tm.put(4, "Karthikeyan");
		tm.put(5, "Mohan");
		tm.put(6, "Vinoth");
		tm.put(7, "Hari Haran");

		System.out.println("Checking value");
		System.out.println("'three' exists: " + tm.containsValue("three"));
	}
}

Output

Checking value
'three' exists: false

Explanation

public boolean containsValue(Object value)
Returns true if this map maps one or more keys to the specified value. More formally, returns true if and only if this map contains at least one mapping to a value v such that (value==null ? v==null : value.equals(v)). This operation will probably require time linear in the map size for most implementations.
Specified by:
containsValue in interface Map<K,V>
Overrides:
containsValue in class AbstractMap<K,V>
Parameters:
value - value whose presence in this map is to be tested
Returns:
true if a mapping to value exists; false otherwise


Related Post

Comments


©candidjava.com