import java.util.*;
class Demo
{
public static void main (String[]args)
{
String s = "aabcdeff";
char[] cha = s.toCharArray();
TreeMap<Character, Integer> tm = new TreeMap<Character, Integer>();
for (char c : cha) {
Integer it = tm.get(c);
// (it!=null)?tm.put(c,1):tm.put(c,it+1);
if (it == null) {
tm.put(c, 1);
} else {
tm.put(c, it + 1);
}
}
StringBuilder ss=new StringBuilder();
Set<Character> keyset = tm.keySet();
Iterator<Character>i=keyset.iterator();
while(i.hasNext())
{
Character ch=i.next();
Integer in=tm.get(ch);
ss.append(ch+"("+in+")");
System.out.print(ss.toString());
}
}
}
我打印出来的结果 试了几次总不对
|