简体   繁体   中英

how to add value into List<Map<String, Object>>?

I'm trying to add a value to an ArrayList .

Here is the code I wrote:

List<Map<String, Object>> list = new ArrayList<>();
list.put(1,"foo", (Object)"bar");

But, this does not work. Anybody have an idea?

List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map = new HashMap<String, Object>();
map.put("foo", "bar");
list.add(map);

private List<Map<String, Object>> map_formula;

To save to database pass this JSON:-

{
"map_formula" : [ 
        {
            "A+" : "if(price<400),\"40000\",0",
            "B" : "",
            "c" : "",
            "d" : "",
            "e" : ""
        }, 
        {
            "poor" : "value for poor",
            "good" : "300",
            "average" : "300",
            "excellent" : "300"
        }
    ]
}

To extract from the database:-

 for (Map<String, Object> stringObjectMap : obj.getMap_formula()) {

                        if (stringObjectMap.containsKey("key_name"){
                            System.err.println("calculation started");
                        }
                    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM