获取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

posted on 2019-09-03 11:35  小白菜好吃  阅读(4342)  评论(0编辑  收藏  举报

导航