Find number of occurrence of each of the unique characters in a string ?
Find number of occurrence of each of the unique characters in a string ?
- In this program an approach using Hashmap in Java.
- Declare a Hashmap in Java of {char, int}.
- Traverse in the string, check if the Hashmap already contains the traversed character or not.
- If it is present, then increase its count using get() and put() function in Hashmap.
- Once the traversal is completed, traverse in the Hashmap and print the character and its frequency.