Map<Character, Integer> map = new HashMap();
for(char c : ch) {
if(map.get(c) == null) {
map.put(c, 1);
} else {
map.put(c, map.get(c)+1);
}
}
for(Map.Entry entry : map.entrySet()) {
System.out.println("Key is "+ entry.getKey() + " Value is " + entry.getValue());
}
I have a String str = "PriyankaTaneja"
I want to count the frequency of characters in the String using map and i want to sort the map in decreasing order of values, that means the character repeating the max number of times should be the first to print.