How to get all the elements out of ArrayList<HashMap<String, String>> android How to get all the elements out of ArrayList<HashMap<String, String>> android sqlite sqlite

How to get all the elements out of ArrayList<HashMap<String, String>> android


for (HashMap<String, String> contact : data1) {    for (Entry<String, String> item : contact.entrySet()) {        String key = item.getKey();        String value = item.getValue();        ... do whatever you want to do to print things    }}


Sample program to achieve what you want .

public class mainClass { public static void main(String[] args){ HashMap<String , String> map1 = new HashMap();  map1.put("ONE", "1");  map1.put("TWO", "2");  map1.put("THREE", "3");  map1.put("FOUR", "4");  map1.put("FIVE", "5");  HashMap<String , String> map2 = new HashMap();  map2.put("ONE", "1");  map2.put("TWO", "2");  map2.put("THREE", "3");  map2.put("FOUR", "4");  map2.put("FIVE", "5"); ArrayList<HashMap<String, String>> getContacts = new ArrayList<HashMap<String, String>>(); getContacts.add(map1); getContacts.add(map2); for(HashMap<String,String> map : getContacts ){     // get your hashmap keys      Set <String>setOfKeys = map.keySet();     Iterator<String> iterator = setOfKeys.iterator();     while (iterator.hasNext()) {         /**          * next() method returns the next key from Iterator instance.          * return type of next() method is Object so we need to do DownCasting to String          */         String key = (String) iterator.next();         /**          * once we know the 'key', we can get the value from the HashMap          * by calling get() method          */          String value = (String)map.get(key);         System.out.println("Key: "+ key+", Value: "+ value);         // store the key + value to whatever you want here           } }   }  }


you can print all the values in data1 using data1.toString()