frequency of number in java using hashmap using getordefault

158

frequency of number in java using hashmap using getordefault -

Map<Character,Integer> frequencies = new HashMap<>();
for (char ch : input.toCharArray()) 
   frequencies.put(ch, frequencies.getOrDefault(ch, 0) + 1);

Comments

Submit
0 Comments