Hash Tables in Java
The Java library provides HashSet and HashMap; the item type for these must provide methods .equals() and .hashCode().
A HashMap, O(1), is a good choice when it is not necessary to be able to access the items in a sorted order; otherwise, use a TreeMap, O(log(n)) .
In Java, a String object caches[The word cache is French for hiding place.] its hash code by storing the hash code in the String object the first time it is computed. Thereafter, the hash code can be gotten quickly. This is trading some space for time.