fork download
  1. import java.util.*;
  2.  
  3. class KeyComparator implements Comparator
  4. {
  5. public int compare(Object a, Object b)
  6. {
  7. if ((char) a > (char) b)
  8. return 1;
  9. else
  10. return -1;
  11. }
  12. }
  13.  
  14. class Tester
  15. {
  16. public static void main(String[] args)
  17. {
  18. Map map = new TreeMap(new KeyComparator());
  19. map.put('B', 3);
  20. map.put('A', 1);
  21. map.put('C', 2);
  22.  
  23. System.out.print(map);
  24. }
  25. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
{A=1, B=3, C=2}