Worked example
String[] words = {"a", "b", "a", "c", "a", "b"};
Map<String, Integer> counts = new HashMap<String, Integer>();
for (int i = 0; i < words.length; i++) {
counts.put(words[i], counts.getOrDefault(words[i], 0) + 1);
}
int max = 0;
for (String key : counts.keySet()) {
if (counts.get(key) > max) {
max = counts.get(key);
}
}
System.out.println(max); // 3 — "a" appears three times
System.out.println(counts.size()); // 3 — three distinct words