简体   繁体   English

如何遍历哈希图数据列表

[英]How to iterate through list of hashmap data

I have list of hashmap. 我有哈希图列表。 I want to iterate through the data. 我想遍历数据。 Kindly help me with an example. 请帮我举个例子。 I have a table where I have months on Y axis and the fields like( MS_Target, HSD_Target, ALPG_Target, Lube_Target) on X axis. 我有一个表,其中我在Y轴上有几个月,而在(X_轴上)有(MS_Target,HSD_Target,ALPG_Target,Lube_Target)字段。 My code is as follows: 我的代码如下:

 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));

}

Likewise I have created hashmap for all months. 同样,我已经创建了所有月份的哈希图。 Also, kindly suggest me what key and value should I take. 另外,请建议我应该采取什么关键和价值。 Please help me out with an example. 请举一个例子帮我。 I have given unique names to all the fields. 我为所有字段都指定了唯一的名称。 eg: apr_MS , apr_HSD etc. My Table is as follows: 例如: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

You can use an iterator on a hashmap see here : 您可以在哈希图中使用迭代器,请参见此处:

Hashmap iteration Hashmap迭代

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM