HELP! * YELLOW=global GREY=local Global HTML version of Foils prepared 4 February 97

Foil 41 The Hashtable class

From Feb 3 Delivered Lecture for Course CPS616 -- Java Lecture 4 -- AWT Through I/O CPS616 spring 1997 -- Feb 3 1997. by Nancy McCracken * See also color IMAGE
Secs 41.7
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.


Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sun Feb 16 1997