This class is similar to the Perl associative array (or hash array with {} brackets). It can store a set of key and value pairs, neither of which can be null.
-
Hashtable staff = new Hashtable();
-
Employee harry = new Employee("Harry Hacker");
-
staff.put("987-98-9996", harry);
|
Values are retrieved by indexing with a key. Like Vectors, Hashtables only store things of type Object and you must cast the result.
-
steve = (Employee) staff.get("149-26-7355");
|
If there was no entry, a null is returned.
|
Performance of the Hashtable can also be affected by giving an initialCapacity and a loadFactor for reallocation.
|