[英]My Hashmap object value list object return only last object i was put in ArrayList<Map<String,Object>>>();
this is my code for detail description. 这是我的详细说明代码。 i get size of Hashmapis ok.
我得到Hashmapis的大小确定。 but when i try to get
ArrayList<Map<String, Object>>>
using key, all the ArryList have size 1. 但是当我尝试使用键获取
ArrayList<Map<String, Object>>>
,所有ArryList的大小均为1。
private ArrayList<Map<String, Object>> settingInObject;
private ArrayList<Map<String, Object>> parentItemList;
private HashMap<String, ArrayList<Map<String, Object>>> childItemList;
settingInObject = new ArrayList<>();
parentItemList = new ArrayList<>();
childItemList = new HashMap<String, ArrayList<Map<String,Object>>>();
ArrayList<Map<String, Object>> arrayList = new ArrayList<Map<String, Object>>();
for (Map<String, Object> objectMap : settingInObject) {
if (objectMap.get("IsCheked").toString().equals("1")) {
if (arrayList.size() > 0) {
childItemList.put(parentItemList.get(parentItemList.size()).get("TitleDesc").toString().trim(), arrayList);
arrayList.clear();
}
parentItemList.add(objectMap);
} else {
arrayList.add(objectMap);
}
}
is there i do something wrong?? 我在做错什么吗?
You are calling 你在打电话
arrayList.clear();
while under arayList you have still reference to added object - in result you are clearing the list that is already put in the map 而在arayList下,您仍然引用添加的对象-结果您正在清除已放入地图中的列表
If you want to have new empty list in arrayList
you need to reinstance it rather 如果要在
arrayList
有新的空列表, arrayList
需要重新实例化
arrayList = new ArrayList<Map<String, Object>>();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.