public static String strCount(String str){
char[] ch = str.toCharArray();
Map<Character, Integer> map = new TreeMap<Character, Integer>();
for (int i = 0; i < ch.length; i++) {
Integer value = map.get(ch[i]);
int count = 1;
if (value != null) {
count = value + 1;
}
map.put(ch[i], count);
}
return toNewString(map);
}
public static String toNewString(Map<Character, Integer> map){
StringBuilder sBuilder = new StringBuilder();
Iterator<java.util.Map.Entry<Character, Integer>> iterator = map.entrySet().iterator();
while (iterator.hasNext()) {
java.util.Map.Entry<Character, Integer> entry = iterator.next();
char ch1 = entry.getKey();
int value = entry.getValue();
sBuilder.append(ch1+"{"+value+"}"+" ");
}
return sBuilder.toString();
}
}