TestHashtable.java
Select all
/* TestHashtable.java David Klick CIS 260 3/23/09 This program demonstrates a few features of the Hashtable class. Note that the datatypes could easily have been reversed within the program so that we were looking up Integers based on String values. */ import java.util.*; public class TestHashtable { public static void main(String[] args) { Hashtable
ht = new Hashtable
(); ht.put(31, "Sally Ford"); ht.put(17, "John Buick"); ht.put(96, "Edna Honda"); ht.put(14, "Bob Chevrolet"); ht.put(22, "Jack Lotus"); ht.put(10, "Henry Toyota"); Collection
coll = ht.values(); for (String s : coll) System.out.println(" " + s); for (int i=0; i<=50; i++) { String s = ht.get(i); if (s != null) { System.out.println(i + ": " + s); ht.remove(i); } } coll = ht.values(); for (String s : coll) System.out.println(" " + s); } } /* Sample output: John Buick Edna Honda Sally Ford Bob Chevrolet Henry Toyota Jack Lotus 10: Henry Toyota 14: Bob Chevrolet 17: John Buick 22: Jack Lotus 31: Sally Ford Edna Honda */