Hi,
Can any one say what is hte difference between
contains and containsValue in hashtable.
Thank you,
With Regards,
Prem
20 seconds with the Java API reference would have lead you immediately to the following statement in the doc for contains:
Note that this method is identical in functionality to containsValue, (which is part of the Map interface in the collections framework).
In fact it was probably quicker to look this up than to create the thread.
In contains we are passing the value . In containsvalue also we are passing the key.What is the major difference in it.
Thank you,
No. You do not pass the key to containsValue, you pass the value. It's EXACTLY the same as contains.
Are you confusing it with containsKey ?
Check out the API documentation
SO,What is the diffrence between the both contains and containsValue.
In both we are passing the value only.
Thank you
For the last time
THERE IS NO DIFFERENCE BETWEEN CONTAINS AND CONTAINSVALUE!
Here (copyright Sun) is the actual source code for containsValse for version 1.6 of Java
/**
* Returns true if this hashtable maps one or more keys to this value.
*
* <p>Note that this method is identical in functionality to {@link
* #contains contains} (which predates the {@link Map} interface).
*
* @param value value whose presence in this hashtable is to be tested
* @return <tt>true</tt> if this map maps one or more keys to the
* specified value
* @throws NullPointerException if the value is <code>null</code>
* @since 1.2
*/
public boolean containsValue(Object value) {
return contains(value);
}
The reason is that Hashtable has been in Java for as long time, with just the contains() method. Later on they introduced the Map interface to update and make consistent all the various classes that held keyed collections. The Map interface defines the containsValue() method, so that had to be added to Hashtable later. As you see from the source code above, they did that by simply calling contains().
Thank you for your clear explanation .
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.