我有一個字符串地圖的字符串,我想排序地圖根據他的價值爲凱F
,但我的代碼沒有這樣做。請指教。比較價值的基礎上的關鍵在地圖列表
Map<String, String> h = null;
Map<String, String> h1 = null;
Map<String, String> h2 = null;
listSummaryMap = new ArrayList<Map<String, String>>();
h = new HashMap<String, String>();
h.put("SUCCESS", "27");
h.put("TOTAL_HOTELS", "86");
h.put("F", "86");
h.put("RESERVATION_MODE", "86");
h.put("PARTNER_NAME", "86");
h1 = new HashMap<String, String>();
h1.put("SUCCESS", "27");
h1.put("TOTAL_HOTELS", "86");
h1.put("F", "36");
h1.put("RESERVATION_MODE", "86");
h1.put("PARTNER_NAME", "86");
h2 = new HashMap<String, String>();
h2.put("SUCCESS", "27");
h2.put("TOTAL_HOTELS", "86");
h2.put("F", "28");
h2.put("RESERVATION_MODE", "86");
h2.put("PARTNER_NAME", "86");
listSummaryMap .add(h);
listSummaryMap .add(h1);
listSummaryMap .add(h2);
Collections.sort(listSummaryMap , new Comparator<Map<String, String>>() {
@Override
public int compare(Map<String, String> o1, Map<String, String> o2) {
return o2.get("F").compareTo(o1.get("F"));
}
});
'Collections.addAll(listSummaryMap,H,H1,H2);'創建的所有地圖之後。 –
謝謝Jekin Kalariya,Eran,每個人 – nostalgiaguy