获取Map中Value(值)的最小值和最大值


public class MapMinMaxvalue {
    public static void main(String[] args) {
        Map<Object, Object> map=new HashMap<Object, Object>();
        map.put("2", 5);
        map.put("47", 2);
        map.put("13", 28);
        map.put("25", 17);
        int length =map.size();
        Collection<Object> c =map.values();
        Object[] obj=c.toArray();
        Arrays.sort(obj);
        System.out.println("获取Map中Value(值)的最小值======"+obj[0]);
        System.out.println("获取Map中Value(值)的最大值====="+obj[length-1]);
    }
}

 

获取Map中Value(值)的最小值======2
获取Map中Value(值)的最大值=====28


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM