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