Lets say I have a string "aaabcccdddd" I have stored each alphabets as keys and each repetition of the character as the value in a hash map. How can I use the map to print out to my console the characters in a descending order. For example= "dddcccaaab"
void str(String s) {
int len = s.length();
Map<Character, Integer> elements = new HashMap<>(Math.min(len, 26));
Map<Character, Integer> sortedByValues;
String concact=""; int b;char a;
for (int i = 0; i < len; i++){
if (!elements.containsKey(s.charAt(i)))
elements.put(s.charAt(i), 1);
else
elements.put(s.charAt(i), elements.get(s.charAt(i)) + 1);}