Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tremaineeto/4da3db39aa14a9dc53c372f4df4ad5e1 to your computer and use it in GitHub Desktop.
Save tremaineeto/4da3db39aa14a9dc53c372f4df4ad5e1 to your computer and use it in GitHub Desktop.
public void keepCountOfCharactersInStringWithGetOrDefault(String str) {
HashMap<Character, Integer> map = new HashMap<>();
for (int i = 0; i < str.length(); i++) {
map.put(str.charAt(i), map.getOrDefault(str.charAt(i), 0) + 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment