public static void main(String[] args) {
String str="abcdekka27qoq";
char[] arr = str.toCharArray();
TreeMap<Character,Integer> t=new TreeMap<>();
for (Character c : arr) {
Integer i = t.get(c);
i=!t.containsKey(c)?1:i+1;
t.put(c, i);
}
for (char c : t.keySet()) {
System.out.print(c+"("+t.get(c)+")");
}
}
|