Java Reference
In-Depth Information
public abstract class Employee
{
private String name;
private String address;
private int number;
public Employee(String name, String address, int number)
{
this.name = name;
this.address = address;
this.number = number;
}
public int hashcode()
{
return number;
}
public boolean equals(Object x)
{
if(x == null || !(x instanceof Employee))
{
return false;
}
else
{
return this.number == ((Employee) x).number;
}
}
}
The java.util.Hashtable class implements a hash table. A Hashtable object has
two attributes that determine how the hash table grows in memory: an initial
capacity and a load factor. The initial capacity of a Hashtable is similar to the
initial capacity of a Vector. It is the initial available memory for the hash table.
Vectors grow by a fixed amount when they become completely filled. Hash
tables would be terribly inefficient if they behaved in this manner. Instead, a
hash table grows when the buckets start to get too many elements in them.
How many is too many? This is determined by the load factor, a value between
0 and 1 that is used in the following formula:
number of entries > capacity * load factor
When the number of entries in the hash table is greater than the load factor
times the capacity, the hash table automatically resizes and rehashes itself.
Suppose, for example, that you have a hash table whose capacity is 100 and
whose load factor is 0.75. The point it resizes occurs after 100 * 0.75 = 75 ele-
ments are added to the hash table. After 75 elements, the hash table grows in
Search WWH ::




Custom Search