【java】hashmap按照key排序

HashMap maptest =new  HashMap();
maptest.put("1天","day1");
maptest.put("5天","day5");
maptest.put("4天","day4");
maptest.put("2天","day2");
maptest.put("3天","day3");
		 
Collection keyset= maptest.keySet();
List list = new ArrayList(keyset);
		 
//对key键值按字典升序排序
Collections.sort(list);
		 
for (int i = 0; i < list.size(); i++) {
    System.out.println("key键---值: "+list.get(i)+","+maptest.get(list.get(i)));
}

 

你可能感兴趣的:(【java】hashmap按照key排序)