版权声明:本博主小白一个,希望各位大神多多指教,相互学习。 https://blog.csdn.net/li1325169021/article/details/87978421
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