【问题标题】:How to iterate over HashMap<String, ArrayList<Record>> in Java? [duplicate]如何在 Java 中迭代 HashMap<String, ArrayList<Record>>? [复制]
【发布时间】:2017-11-01 23:21:10
【问题描述】:

我想访问我在 HashMap 中创建的记录。
由于某些要求,我无法创建新的数据结构来保存我的数据。

private HashMap<String, ArrayList<Record>> customerInfoTable = new 
HashMap<String, ArrayList<Record>>();

【问题讨论】:

  • 你尝试过什么,你在哪里卡住了?
  • for (List&lt;Record&gt; rs : customerInfoTable.values()) for (Record r : rs) { ... }

标签: java generics collections hashmap


【解决方案1】:
  1. getKeyList() 获取键列表,然后为每个获取值
  2. 迭代器> it = map.entrySet().iterator(); 而(it.hasNext()){ Map.Entry entry = it.next();}

【讨论】:

    猜你喜欢
    • 2011-12-02
    • 2016-01-13
    • 2014-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-08
    • 2017-08-30
    相关资源
    最近更新 更多