Loop through an ArrayList of HashMaps Java
arraylist, hashmap, java
Solution
the `[]` operator can only be used on arrays. List has a `get(int index)` method to get the element at a given index:
for (String key : myList.get(a).keySet()) {
...
}
Java classes are documented: http://docs.oracle.com/javase/6/docs/api/
Problem
``` ArrayList<HashMap<String, Integer>> myList = new ArrayList<HashMap<String, Integer>>(); HashMap<String, Integer> check = new HashMap<String, Integer>(); ``` I have some number of hashmaps in my array list and I want to compare the hashmaps for duplicates like this 0,1 0,2 0,3 0,4....1,2 1,3 1,4.....2,3 2,4 etc. I was doing a nested for loop to so this but got stuck on how to access the hashmaps and tried this ``` for (int a =0; a<myList.size();a++){ for(int b=a+1; b<myList.size();b++){ for (String key : myList[a].check.keySet()) } } ``` But this does not work. How do I acess all the keys of my hashmap if their in the arraylist? How can I accomplish this?