Example #1
0
  public static void main(String[] args) {
    Scanner keyboard = new Scanner(System.in);
    System.out.print("Enter the size of the array:  ");
    int arrayLength = keyboard.nextInt(); // 20
    Hashtable table = new Hashtable(arrayLength);

    System.out.print("\nEnter the number of items:  ");
    int numItems = keyboard.nextInt(); // 15
    System.out.print("\nThe Load Factor is " + (double) numItems / arrayLength);
    System.out.println();
    for (int i = 0; i < numItems; i++) table.add("Item " + i);
    System.out.println();
    System.out.print("Search for:  Item ");
    int i = keyboard.nextInt();
    String key = "Item " + i;
    if (!table.contains(key)) System.out.println(key + " NOT found");
  }