Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retriving the values of Map inside List

Tags:

java

ArrayList<HashMap<String, Object>> list = ArrayList<HashMap<String, Object>>()

I have an array list which contains an hashmap, i am able to get the position of my List , now how would i get the key and value of the object in my List.

@Override
public View getDropDownView() {        
    System.out.println(data.get(position)); // i am getting my List Objects 
}

// The below is the output of data.get(position)

 {"title":"hello"}, => 0 
 {"title":"hello1"}, => 1
 {"title":"hello2"}, => 2
 {"title":"hello3"}, => 3
like image 820
theJava Avatar asked Jan 29 '26 07:01

theJava


1 Answers

Try this out :

List<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();

    for (Map element : list) {
        Set<Map.Entry<String, Object>> entrySet = element.entrySet();
        for (Map.Entry<String, Object> mapEntry : entrySet) {
            System.out.println("Key is : " + mapEntry.getKey());
            System.out.println("Value is : " + mapEntry.getValue());
        }
    }
like image 56
Ankur Shanbhag Avatar answered Jan 30 '26 21:01

Ankur Shanbhag



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!