Basic HTML version of Foils prepared 18 May 97

Foil 23 The Hashtable class

From Java Tutorial - Spring 1997 Part 4: Multithreading, useful Java classes, I/O, Networking, and the future Peking Tutorial, Web Certificate -- Spring-Summer 1997. by Nancy J. McCracken,Geoffrey C. Fox


1 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);
2 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");
3 If there was no entry, a null is returned.
4 Performance of the Hashtable can also 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 Thu Jan 8 1998