Ad
  • Custom User Avatar

    Instead of checking the current value you could use the merge function instead.
    For example:
    HashMap<String, Integer> count = new HashMap<>();
    Stream.of(str1.split("")).forEach(letter -> count.merge(letter, 1, Integer::sum));