public class Test3 {
public static void main(String[] args) {
Map<String, Info> map = new HashMap<>();
Info info1 = new Info("xxxx", "hhhh", "1980-11-01");
Info info2 = new Info("xxxx", "hhhh", "1983-11-22");
Info info3 = new Info("xxxx", "hhhh", "1925-11-01");
map.put("小杰杰", info1);
map.put("你好", info2);
map.put("你好1", info3);
List<Map.Entry<String,Info>> list = new ArrayList<Map.Entry<String,Info>>(map.entrySet());
Collections.sort(list, new Comparator<Map.Entry<String, Info>>() {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
public int compare(Entry<String, Info> o1, Entry<String, Info> o2) {
try {
Date dt1 = format.parse(o1.getValue().getTime());
Date dt2 = format.parse(o2.getValue().getTime());
if (dt1.getTime() > dt2.getTime()) {
return 1;
} else if (dt1.getTime() < dt2.getTime()) {
return -1;
} else {
return 0;
}
} catch (Exception e) {
e.printStackTrace();
}
return 0;
};
});
for(Map.Entry<String,Info> mapping : list){
System.out.println(mapping.getKey()+" : "+mapping.getValue());
}
}