Java Reference
In-Depth Information
Output
Romeo->java.awt.Color[r=0,g=255,b=0]
Eve->java.awt.Color[r=255,g=175,b=175]
Adam->java.awt.Color[r=0,g=0,b=255]
Juliet->java.awt.Color[r=255,g=175,b=175]
S ELF C HECK
3. What is the difference between a set and a map?
4. Why is the collection of the keys of a map a set?
16.3 Hash Tables
In this section, you will see how the technique of hashing can be used to find
elements in a data structure quickly, without making a linear search through all
elements. Hashing gives rise to the hash table, which can be used to implement sets
and maps.
A hash function is a function that computes an integer value, the hash code, from an
object, in such a way that different objects are likely to yield different hash codes.
The Object class has a hashCode method that other classes need to redefine. The
call
int h = x.hashCode();
computes the hash code of the object x .
A hash function computes an integer value from an object.
707
Search WWH ::




Custom Search