【问题标题】:How to iterate through list of hashmap data如何遍历哈希图数据列表
【发布时间】:2012-04-11 10:55:28
【问题描述】:

我有哈希图列表。我想遍历数据。请帮我举个例子。 我有一张表,在 Y 轴上有几个月,在 X 轴上有字段(MS_Target、HSD_Target、ALPG_Target、Lube_Target)。 我的代码如下:

 List<Map<String, Integer>> ListofHash = new ArrayList<Map<String, Integer>>();

        {

        for (int i = 0; i < 10; i++) 
          {
          Map<String, Integer> mMap = new HashMap<String, Integer>();

          mMap.put(String.valueOf(i), Integer.valueOf( + i));

          ListofHash.add(mMap); 
           }
      for (Map<String, Integer> map : ListofHash)
            {
            for (String key : map.keySet())
             {
               System.out.println(map.get(key));
          }
      }

HashMap <String,Integer> april= new HashMap <String,Integer>();

    april.put("aprMS",new Integer(1));
    april.put("aprHSD",new Integer(2));
    april.put("aprAlpg",new Integer(3));
    april.put("aprLubes",new Integer(4));

HashMap <String, Integer> may= new HashMap <String, Integer>();

    may.put("mayMS",new Integer(1));
    may.put("mayHSD",new Integer(2));
    may.put("mayAlpg",new Integer(3));
    may.put("mayLubes",new Integer(4));

}

同样,我已经为所有月份创建了 hashmap。 另外,请建议我应该采用什么键和值。 请帮我举个例子。 我为所有字段赋予了唯一的名称。 例如: apr_MS , apr_HSD 等。 我的表如下:

Month         MS_Target     HSD_Target     ALPG_Target        Lubes_Target
April
May 
June
July 
August
September
October
November
December
January
February 
March

【问题讨论】:

    标签: jsp loops hashmap


    【解决方案1】:

    您可以在 hashmap 上使用迭代器,请参见此处:

    Hashmap iteration

    【讨论】:

    • 感谢您的帖子,我提到的上述代码是否正确??......你能给我一个与我的示例相关的示例代码吗?
    猜你喜欢
    • 1970-01-01
    • 2019-03-11
    • 1970-01-01
    • 2014-01-21
    • 1970-01-01
    • 2014-06-01
    • 1970-01-01
    • 2016-09-03
    相关资源
    最近更新 更多