java map裡面進行ASCII 碼從小到大排序(字典序)
阿新 • • 發佈:2020-06-22
public static String getAsciiSort(Map<String, Object> map) {
List<Entry<String, Object>> infoIds = new ArrayList<Entry<String, Object>>(map.entrySet());
// 對所有傳入引數按照欄位名的 ASCII 碼從小到大排序(字典序)
Collections.sort(infoIds, new Comparator<Entry<String, Object>>() {public int compare(Map.Entry<String, Object> o1, Map.Entry<String, Object> o2) {
return ((String) o1.getKey()).compareToIgnoreCase((String) o2.getKey());
}
});
}