Map汇合

1.依据value获取对应key

value不存在反复景象下能够应用

/**由value获取key*/    public static String getKeyByValue(Map map, Object value) {        String keys="";        Iterator it = map.entrySet().iterator();        while (it.hasNext()) {            Map.Entry entry = (Map.Entry) it.next();            Object obj = entry.getValue();            if (obj != null && obj.equals(value)) {                keys=(String) entry.getKey();            }        }        return keys;    }

运行后果:

2.获取Map汇合value的最大值

Map汇合的value须要为Integer类型

public static Object getMaxValue(Map<String, Integer> map) {        if (map == null)            return null;        int length =map.size();        Collection<Integer> c = map.values();        Object[] obj = c.toArray();        Arrays.sort(obj);        return obj[length-1];    }

运行后果: