hashMap 获取里面value最大的值得key
作者:互联网
public static void main(String[] args) { Map<String, Integer> map = new HashMap(); map.put("1", 8); map.put("2", 12); map.put("3", 53); map.put("4", 33); map.put("5", 11); map.put("6", 3); map.put("7", 3); Set<String> set=map.keySet(); map.entrySet(); List<Map.Entry<String,Integer>> list = new ArrayList(map.entrySet()); Collections.sort(list, (o1, o2) -> (o2.getValue() - o1.getValue()));//升序 System.out.println(list.get(0).getKey()); }
标签:map,hashMap,entrySet,list,value,getValue,key,put,new 来源: https://blog.csdn.net/forever_together/article/details/116125047