java - containsValue vs contains method of Hashtable -
whats difference between containsvalue , contains method of hashtable http://docs.oracle.com/javase/7/docs/api/java/util/hashtable.html
there isn't one. emphasis mine.
returns true if hashtable maps 1 or more keys value. note this method identical in functionality
contains(which predates map interface).
so can use either one, perfer containsvalue() because bit more self-explanatory, that's me.
the reason there 2 different methods same thing because hashtable implements map<k, v> interface. don't know if you've used interfaces yet, classes implement interface required have methods defined in interface. so, because map has definition boolean containsvalue(object value); classes implement (like hashtable) has have method. that's why containsvalue() exists.
then why have have contains()? well, that's because contains() existed before map interface existed (see documentation snippet above). contains() came first, that's why has of functionality. when map interface added class had add containsvalue() method, , didn't want duplicate code in contains method, called it.
Comments
Post a Comment