Basic HTML version of Foils prepared 17 Nov 97

Foil 26 The Hashtable class

From Java Tutorial, July 1, 1996 CEWES Tutorial, CPS606, JSU Class CSC499 -- July 22-25 1997, Fall 97. by Nancy J. McCracken,Geoffrey C. Fox, Tom Scavo


This class is similar to a Perl associative array (or hash). It can store a set of key-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 objects of type Object, so you must cast the result:
steve = (Employee) staff.get("149-26-7355");
If there is no entry, a null value is returned.
Performance of the Hashtable can 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 Wed Apr 1 1998