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
- Implement a word count: count occurrences of words in a string.
- Demonstrate why custom keys need consistent
equals
/hashCode
.