Java - HashMap

HashMap

import java.util.*;
Map ages = new HashMap<>();
ages.put("Ada", 36);
for (Map.Entry e : ages.entrySet()) {
  System.out.println(e.getKey()+": "+e.getValue());
}

Ensure keys have stable equals/hashCode implementations.

Try it

  1. Implement a word count: count occurrences of words in a string.
  2. Demonstrate why custom keys need consistent equals/hashCode.