Find the Biggest number in HashSet/HashMap java(在 HashSet/HashMap java中找到最大的数)
问题描述
我想在 HashSet 和 HashMap 中找到最大的数.假设我的 HashSet 中有数字 [22,6763,32,42,33],我想在当前的 HashSet 中找到最大的数字..我该怎么做?HashMap 也一样.我希望你能帮助我.谢谢你.
I would like to find the biggest number in HashSet and HashMap. Say I have the number [22,6763,32,42,33] in my HashSet and I want to find the largest number in my current HashSet..how would i do this? and Same thing for the HashMap as well. I hope you can help me with it. Thank you.
推荐答案
你可以使用Collections.max(Collection)
找出任何集合中的最大元素.同样,对于 HashMap
,您可以在其 keySet()
或 values()
,取决于您想要最大键还是最大值.
You can use Collections.max(Collection)
to find the maximum element out of any collection.
Similarly, for a HashMap
, you can use the same method on its keySet()
or values()
, depending upon whether you want maximum key, or maximum value.
此外,如果您愿意,可以使用 TreeSet
和 TreeMap
相反,它以排序键顺序存储元素.
Also, if you want as such, you can use a TreeSet
and TreeMap
instead, that stores the elements in sorted key order.
这篇关于在 HashSet/HashMap java中找到最大的数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 HashSet/HashMap java中找到最大的数


- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01