18.3 Associative Memory
An associative memory associates a key with a value. Java provides the general interface Map for data structures of this kind with important operations like put(key, value) to create an association and get(key) to get an associated value.
18.3.1 The HashMap and TreeMap Classes and Static Map Methods
The Java library implements associative memory with a few classes, and we’ll focus our attention on two important classes first:
-
A quick implementation is the hashtable, which is implemented in Java by java.util.HashMap . [ 222 ] The key objects must be “hashable” (i.e., must implement equals(...) and hashCode() concretely). A special interface for the elements isn’t necessary.
-
In addition, the java.util.TreeMap ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access