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 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.

Contents    Page-10    Prev    Next    Page+10    Index