public static void main(String[] args) throws InterruptedException {
Map<Integer, Integer> map = new HashMap<>();
map.put(1,1);
map.put(2,2);
map.put(3,3);
map.put(4,4);
System.out.println(getMaxValue(map));
}
/**
* 求Map<K,V>中Value(值)的最小值
*
* @param map
* @return
*/
public static Object getMinValue(Map<Integer, Integer> map) {
if (map == null)
return null;
Collection<Integer> c = map.values();
Object[] obj = c.toArray();
Arrays.sort(obj);
return obj[0];
}
/**
* 求Map<K,V>中Value(值)的最大值
*
* @param map
* @return
*/
public static Object getMaxValue(Map<Integer, Integer> map) {
if (map == null)
return null;
int length =map.size();
Collection<Integer> c = map.values();
Object[] obj = c.toArray();
Arrays.sort(obj);
return obj[length-1];
}
java获取map中value的最大值
于 2021-03-05 15:13:34 首次发布