java - 如何从 java 中 POJO 中的 ArrayList 获取特定值
问题描述
Key : 22 Value: Abey
Key : 22 Value : Dawn
Key : 22 Value : Sherry
Key : 22 Value : Sherry
Key : 22 Value : Sherry
我只想打印带有雪利酒的钥匙,如何使用 Java 来打印?
更改问题的标题,因为 HashMap 不存储重复的键
解决方案
HashMap 不接受重复的键。仅重复值。在您的方法中,您无法存储所显示的所有记录。例如:
Map<Integer, String> map = new HashMap<>();
map.put(22, "Abey");
map.put(22, "Dawn");
map.put(22, "Sherry");
map.put(22, "Sherry");
map.put(22, "Sherry");
当您打印 HashMap 的输出时。您只会得到一个输出,因为相同的键将替换为最新值。
输出:
{22=Sherry}
如果您真的想存储重复键,请了解有关如何在 HashMap 中存储重复键的更多信息。
推荐阅读
- java - 如果选中单选按钮,如何检查复选框
- c# - Automapper :- 映射列表
要列出的属性 在一个班级里面 - python - Python 请求,我如何执行多个 POST 操作
- gremlin - 给定日期的 Gremlin 星期几
- rotation - LiveCode 中的旋转和调整大小
- heroku - Aqueduct heroku 部署问题
- php - PHP使用类中的array_push函数将项目添加到目录
- react-native - 从窗口组件反应导航全屏模式
- c++ - Concurrent_hash_map 实现抛出 SIGSEGV
- python - 不正确的 if-else 语句