Basic HTML version of Foils prepared Sept 21 1998

Foil 26 The Hashtable class

From Java Tutorial 98- 4: Multi-Treading, Useful Java Classes, I/O and Networking NAVO Tutorial -- Sept 23 1998. by Geoffrey C. Fox, Nancy McCracken


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.
  • Hashtable staff = new Hashtable();
  • Employee harry = new Employee("Harry Hacker");
  • staff.put( "987-98-9996", harry );
2 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");
3 If there is no entry, a null value is returned.
4 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 Sat Nov 28 1998