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


1 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.
2 Hashtable staff = new Hashtable();
3 Employee harry = new Employee("Harry Hacker");
4 staff.put( "987-98-9996", harry );
5 Values are retrieved by indexing with a key. Like Vectors, Hashtables only store objects of type Object, so you must cast the result:
6 steve = (Employee) staff.get("149-26-7355");
7 If there is no entry, a null value is returned.
8 Performance of the Hashtable can be affected by giving an initialCapacity and a loadFactor for reallocation.

in Table To:


© 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