Java map取value最大值和最小值

    /**
     * 求Map<K,V>中Value(值)的最小值
     * 
     * @param map
     * @return
     */
    public static Object getMinValue(Map<Integer, Integer> map) {
        if (map == null)
            return null;
        Collection<Integer> c = map.values();
        Object[] obj = c.toArray();
        Arrays.sort(obj);
        return obj[0];
    }
    /**
     * 求Map<K,V>中Value(值)的最大值
     * 
     * @param map
     * @return
     */
    public static Object getMaxValue(Map<Integer, 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];
    }

 

posted @ 2014-11-24 09:53  justin_xiaoshuai  阅读(8837)  评论(0编辑  收藏  举报