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 AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01