How to get value stored in ArrayList<HashMap<key,value>>?
52,745
Solution 1
Your code has bit different for this line,
for(Entry<String, String> mapEntry: map.entrySet())
Try this and let me know what happen,
for (HashMap<String, String> map : mylist)
for (Entry<String, String> mapEntry : map.entrySet())
{
String key = mapEntry.getKey();
String value = mapEntry.getValue();
}
Solution 2
Simple way
Try this i hope it works for u also...
ArrayList<HashMap<String,String>> arraylist;
for (int i=0;i<arraylist.size();i++)
{
HashMap<String, String> hashmap= arraylist.get(i);
String string= hashmap.get("Your_Key_Name");
}
Solution 3
try this
for(HashMap<String,String> map:myList){
for(String str:map.keySet()){
String key=str;
String value=map.get(str);
}
}
Solution 4
According to this thread : Iterate through a HashMap you have to use HashMap.entrySet()
method.
You can take a look here too : http://developer.android.com/reference/java/util/HashMap.html
Solution 5
Try this instead:
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
for(HashMap<String, String> map: mylist) {
for(Entry<String, String> mapEntry: map.entrySet()) {
String key = mapEntry.getKey();
String value = mapEntry.getValue();
}
}
Note the line that says for(Entry<String, String> mapEntry: map.entrySet())
Author by
Roshni Kyada
Updated on April 18, 2020Comments
-
Roshni Kyada about 4 years
I have ArrayList>. In another activity I want to access all values stored in ArrayList>.
I have tried following code:
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>(); for(Hashmap<String, String> map: mylist) { for(Entry<String, String> mapEntry: map) { String key = mapEntry.getKey(); String value = mapEntry.getValue(); } }
but it shows an error at
for(Entry<String, String> mapEntry: map)
that it only interate over Array.