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的最大值
最新推荐文章于 2024-01-25 17:43:54 发布
本文介绍了一种在Java中从Map<Integer,Integer>类型的数据结构中找出最大值的方法。通过将Map的值集合转换为数组并进行排序,从而实现了快速获取最大值的功能。
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
Langchain-Chatchat
AI应用
Langchain
Langchain-Chatchat 是一个基于 ChatGLM 等大语言模型和 Langchain 应用框架实现的开源项目,旨在构建一个可以离线部署的本地知识库问答系统。它通过检索增强生成 (RAG) 的方法,让用户能够以自然语言与本地文件、数据库或搜索引擎进行交互,并支持多种大模型和向量数据库的集成,以及提供 WebUI 和 API 服务
636

被折叠的 条评论
为什么被折叠?



