Two "hash" classes, ``++Hashtable++``, and ``++ConcurrentHashMap++`` offer ``++contains++`` methods. One might naively assume that the ``++contains++`` method searches both keys and values for its argument. And one would be wrong. Because these legacy methods search only values, they are likely to mislead maintainers even if the original coder understood precisely what's going on.


== Noncompliant Code Example

----
Hashtable<String,Object> ht = new Hashtable<>();
// ...

if (ht.contains(foo)) {  // Noncompliant
  // ...
}
----


== Compliant Solution

----
Hashtable<String,Object> ht = new Hashtable<>();
// ...

if (ht.containsValue(foo)) {
  // ...
}
----



ifdef::rspecator-view[]
== Comments And Links
(visible only on this page)

include::comments-and-links.adoc[]
endif::rspecator-view[]
