Iterate over List> in Java

后端 未结 4 1180
盖世英雄少女心
盖世英雄少女心 2020-12-17 08:16

I\'m trying to iterate List> in Java. However, I\'m not able to iterate it properly. Can any one guide me?

Itera         


        
4条回答
  •  既然无缘
    2020-12-17 08:52

    public static void main(String[] args) {
            List> myListOfMaps = new ArrayList>();
            Map map1 = new HashMap();
            map1.put("Fname", "Ankur");
    
            Map map2 = new HashMap();
            map2.put("Lname", "Singhal");
    
            myListOfMaps.add(map1);
            myListOfMaps.add(map2);
    
            for (int i = 0 ; i < myListOfMaps.size() ; i++) {
                Map myMap = myListOfMaps.get(i);
                System.out.println("Data For Map" + i);
                for (Entry entrySet : myMap.entrySet()) {
                    System.out.println("Key = " + entrySet.getKey() + " , Value = " + entrySet.getValue());
                }
            }
        }
    

    output

    Data For Map0
    Key = Fname , Value = Ankur
    Data For Map1
    Key = Lname , Value = Singhal
    

提交回复
热议问题