时间:2020-11-11 11:15:36 | 栏目:JAVA代码 | 点击:次
return entries;
}
/**
* @param h
* @return
* 实现对map按照key排序
*/
@SuppressWarnings("unchecked")
public static Map.Entry[] getSortedHashtableByKey(Map h) {
Set set = h.entrySet();
Map.Entry[] entries = (Map.Entry[]) set.toArray(new Map.Entry[set
.size()]);
Arrays.sort(entries, new Comparator() {
public int compare(Object arg0, Object arg1) {
Object key1 = ((Map.Entry) arg0).getKey();
Object key2 = ((Map.Entry) arg1).getKey();
return ((Comparable) key1).compareTo(key2);
}
});
return entries;
}