Comment

Comment by _old_dude_

yes, Java 8 adds a bunch of methods to ArrayList and HashMap that makes the code a little more high level.

There is also another variation, using map.getOrDefault()

  words.forEach(word -> {
      map.put(word, map.getOrDefault(word, 0) + 1);
  });
and then at some points you discover the Stream API

  var map = words.stream().collect(Collectors.groupingBy(w -> w, Collectors.counting()));
parent _old_dude_ 7 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton