public class GiveMeMore {
private static final int counter = 1;
public static void main(String[] args) {
try {
BufferedReader in = new BufferedReader(new InputStreamReader(
System.in));
System.out.print("请输入:");
String text = in.readLine();
char[] a = text.toCharArray();
Map m = new TreeMap();
for (int i = 0; i < a.length; i++) {
if (!m.containsKey(a[i])) {
m.put(a[i], counter);
} else {
//int num = m.get(a[i]);
int num =Integer.parseInt(m.get(a[i]).toString()) ;
m.put(a[i], num + 1);
}
}
System.out.println(m);
List arrayList = new ArrayList(m.entrySet());
Collections.sort(arrayList, new Comparator(){
public int compare(Object o1, Object o2) {
Map.Entry obj1 = (Map.Entry) o1;
Map.Entry obj2 = (Map.Entry) o2;
return ((Integer) obj2.getValue()).compareTo((Integer)obj1.getValue());
}
});
System.out.println(arrayList);
} catch (Exception e) {
e.printStackTrace();
}
}
}