我喜欢的一个HashMap排序方法

Map hashMap = new HashMap();

List arrayList = new ArrayList(hashMap.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 (obj1.getKey()).toString().compareTo(obj2.getKey());
   }
  });

你可能感兴趣的:(HashMap)