public static void main(String[] args) { Map<String, String> mapsort = new TreeMap<String, String>( new Comparator<String>() { public int compare(String obj1, String obj2) { // 降序排序 return obj2.compareTo(obj1); } }); Map<String,String> map = new HashMap<String, String>(); map.put("2018-04", "123"); map.put("2018-01", "123"); map.put("2018-05", "123"); map.put("2018-02", "123"); map.put("2018-06", "123"); mapsort.putAll(map); for (String key : mapsort.keySet()) { System.out.println("Key = " + key); } } //防止顺序错乱 mapsort=JSON.parseObject(mapsort.toString(),new TypeReference<TreeMap<String, String>>(){} ,Feature.OrderedField);