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

public class MapMinMaxvalue {

public static void main(String[] args) {

Map map=new HashMap();

map.put("2", 5);

map.put("47", 2);

map.put("13", 28);

map.put("25", 17);

int length =map.size();

Collection 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

public class MapMinMaxvalue { public static void main(String[] args) { Map map=new HashMap(); map.put("2", 5); map.put("47", 2); map.put("13", 28); map.put("25", 17); int length =map.size(); Collection 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
经验分享 程序员 微信小程序 职场和发展