How to get a HashMap value with three values(如何获取具有三个值的 HashMap 值)
问题描述
如果我有一个带有这样键的 HashMap:[pubDate, title, link]
和这样的值(例子):
If I have a HashMap with a such key:
[pubDate, title, link]
and such value(example):
[Thu, 03 Jan 2013 21:50:02 +0100, Transferts - YBX : ''Je change de dimension'', http://www.link.fr/info/link_informations.html]
我可以检索链接 http://www.link.fr/info/link_informations.html
吗?代码:
Can I retrieve the link http://www.link.fr/info/link_informations.html
?
Code:
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
map.put(KEY_TITLE, parser.getValue(e, KEY_TITLE));
map.put(KEY_LINK, parser.getValue(e, KEY_LINK));
map.put(KEY_DATE, parser.getValue(e, KEY_DATE));
//map.put(KEY_DESC, parser.getValue(e, KEY_DESC));
// adding HashList to ArrayList
menuItems.add(map);
}
推荐答案
我刚遇到同样的问题,决定将我的密钥映射到 Entry.这允许地图提供相同的索引功能,同时具有与键关联的多个属性.我认为创建单独的类或嵌套映射是一个更简洁的解决方案.
I just faced the same issue and decided to map my key to an Entry. This allows for the same indexing features provided by a map while having more than one property associated with a key. I think it's a much neater solution that creating a separate class or nesting maps.
Map<String, Entry<Action, Boolean>> actionMap = new HashMap<String, Entry<Action, Boolean>>();
actionMap.put("action_name", new SimpleEntry(action, true));
以后使用数据:
Entry<Action, Boolean> actionMapEntry = actionMap.get("action_name");
if(actionMapEntry.value()) actionMapEntry.key().applyAction();
我个人对此的使用是命名函数的映射.按名称选择函数后,将运行该函数,布尔值将确定处理过程中是否需要清理.
My personal use of this was a map of named functions. Having selected the function by name, the function would be run and the boolean would determine whether or not cleanup was needed in processing.
这篇关于如何获取具有三个值的 HashMap 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何获取具有三个值的 HashMap 值


基础教程推荐
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 降序排序:Java Map 2022-01-01