import java.util.*; class Word { public static void main(String[] args) { String word = args[0]; Map d = new HashMap(); for (int i = 0; i < word.length(); i++) { String c = word.substring(i, i+1); System.out.println( c ); if (! d.containsKey(c)) { d.put(c, new Letter(c)); } (d.get(c)).addOne(); } System.out.println( d ); ArrayList letters = new ArrayList(); for (String key : d.keySet()) { Letter letter = d.get(key); letters.add(letter); } System.out.println( letters ); Collections.sort( letters ); System.out.println( letters ); } } class Letter implements Comparable { String c; int count; public int compareTo(Letter other) { if (this.count > other.count) return -1; else if (this.count < other.count) return 1; else return this.c.compareTo(other.c); } Letter(String c) { this.c = c; } void addOne() { this.count += 1; } public String toString() { return "(" + c + ":" + count + ")"; } }