1 2 3 4 5 6 7 8 9 10 11 12 13 |
public void testMap() { // Comparator.reverseOrder()倒序排序 Map<BigDecimal, String> infoMap = new TreeMap<>(Comparator.reverseOrder()); infoMap.put(new BigDecimal(1), "Str1"); infoMap.put(new BigDecimal(3), "Str3"); infoMap.put(new BigDecimal(2), "Str2"); infoMap.put(new BigDecimal(4), "Str4"); for (Map.Entry<BigDecimal, String> entry : infoMap.entrySet()) { System.out.println(entry.getKey() + ":" + entry.getValue()); } } |
结果
1 2 3 4 |
4:Str4 3:Str3 2:Str2 1:Str1 |
0