1The number of times a character is repeated in a string is known as letter(character) frequency.
1Map -- Frequency of Characters
2Write a method that prints the frequency of each character from a String
3
4Solution:
5public static void FrequencyTest(String str ) {
6 Map<Character, Integer> map = new LinkedHashMap<>();
7 for (Character each : str.toCharArray()) {
8 if (map.containsKey(each)) {
9 map.put(each, map.get(each) + 1);
10 } else {
11map.put(each, 1);
12 }
13 }
14 System.out.println(map);
15 }