Java program to find the number of occurances of a character in the given String text

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Thanks for the effort. I found this solution working for diverse inputs:
int count =0;

HashMap<Character, Integer> map = new HashMap<>();

for (char c :s.toCharArray()) {
if(!map.containsKey(c)){
map.put(c, 1);
}else {
count = map.get(c);
count++;
map.put(c, count);

}
}
for (Character key : map.keySet()) {
System.out.print(key + ""+ map.get(key));
}

TheJami