frequency of characters map

Solutions on MaxInterview for frequency of characters map by the best coders in the world

showing results for - "frequency of characters map"
Jonas
13 Jan 2016
1The number of times a character is repeated in a string is known as letter(character) frequency.
Klara
03 Jan 2019
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    }