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中找到最大的数
基础教程推荐
- Maven:无效的目标版本:10 2022-01-01
- 控制台应用程序中的 Java 键盘输入解析 2022-01-01
- doFilter()是在servlet的工作完成之前还是之后执行的? 2022-01-01
- 将 double 转换为 Int,向下舍入 2022-01-01
- 将 Windows 证书导入 Java 2022-01-01
- Java ECDSAwithSHA256 签名长度不一致 2022-01-01
- 在springboot中如何给mybatis加拦截器 2023-04-29
- JPA惰性列表上的流 2022-01-01
- 如何在相机中应用自定义滤镜 [Surfaceview 预览]. 2022-01-01
- 在java中使用xpath和selenium解析HTML表格数据 2022-01-01
