HashMap的两种排序方式
java 对map或hashmap排序的两种方法 http://www.yihaomen.com/article/java/312.htm
http://www.cnblogs.com/lovebread/archive/2009/11/23/1609121.html
Map<String, Integer> map = new HashMap<String, Integer>();map.put("d", 2);map.put("c", 1);map.put("b", 1);map.put("a", 3);List<Map.Entry<String, Integer>> infoIds = new ArrayList<Map.Entry<String, Integer>>(map.entrySet());//排序前for (int i = 0; i < infoIds.size(); i++) { String id = infoIds.get(i).toString(); System.out.println(id);}//d 2//c 1//b 1//a 3//排序Collections.sort(infoIds, new Comparator<Map.Entry<String, Integer>>() { public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) { //return (o2.getValue() - o1.getValue()); return (o1.getKey()).toString().compareTo(o2.getKey()); }}); //排序后for (int i = 0; i < infoIds.size(); i++) { String id = infoIds.get(i).toString(); System.out.println(id);}