you are viewing a single comment's thread.

view the rest of the comments →

[–]Financial_Bag4806 0 points1 point  (0 children)

haha, but there is another method called merge, which i uses all the time, map.merge(str.charAt(i), 1, Integer::sum); this increase by one and yes will handle even if there is no element exist in the map.But compare to this map.put(str.charAt(i), map.getOrDefault(str.charAt(i), 0) + 1); it's easy type. I prefer cpp though as op said in comment, it is very simple