将包含Hashmap的Array的String转换为Arraylist

时间:2015-11-01 11:15:14

标签: android arraylist

我有包含Hasmap的Arraylist字符串。需要将其转换为Hashmap的Arraylist。

[
    {
        created_by=null,
        title=Hello,
        description=Thisistestdescription,
        category=English,
        logo_url=null,
        id=6,
        url=null,
        modified_by=null,
        date_created=null,
        date_modified=null,
        category_id=2
    },
    {
        created_by=null,
        title=Test1,
        description=Thisistestdescription,
        category=English,
        logo_url=null,
        id=7,
        url=null,
        modified_by=null,
        date_created=null,
        date_modified=null,
        category_id=2
    },
    {
        created_by=null,
        title=open,
        description=Thisistestdescription,
        category=English,
        logo_url=null,
        id=8,
        url=null,
        modified_by=null,
        date_created=null,
        date_modified=null,
        category_id=2
    }
]

1 个答案:

答案 0 :(得分:0)

要将arraylist转换为hashmap,请遍历ArrayList,并将值插入HashMap。

ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
        HashMap<String, String> n = new HashMap<String, String>();
        n.put("key1", "value1");
        n.put("key2", "value2");
        list.add(n);

        HashMap<String, String> map = list.get(0);

        String strArr[] = new String[map.size()];
        int i = 0;
        for (HashMap<String, String> hash : list) {
            for (String current : hash.values()) {
                strArr[i] = current;
                i++;
            }
        }