为什么我的HashMap类型的ArrayList放入值后给出错误的数据?

I'm putting some data into HashMap<Integer, String> and then adding this hashMap into an ArrayList<HashMap<Integer, String>> but when I console the data after adding into array it always give the last added data to its size.

Here you can see logCat data which am I getting. enter image description here

请检查我做错了什么?

    HashMap<Integer, String> hashMap = new HashMap<Integer, String>();
    ArrayList<HashMap<Integer, String>> imgMapList = new ArrayList<>();

for (DataSnapshot snapshot : dataSnapshot.getChildren()) { //runs 2 time

                        int inc = 0;
                        hashMap.clear();
                        for (DataSnapshot snapshotEvd : snapshot.child("evidence").getChildren()) { //runs 3 time
                            String claimedEvdImgURL = snapshotEvd.getValue(String.class);

                            hashMap.put(inc, claimedEvdImgURL);
                            inc = inc + 1;
                        }

                        imgMapList.add(hashMap);

                        Log.i(">>>", "hashMap:" +  hashMap);

                        Log.i(">>>", "imgMapList:" +  imgMapList);

                    }
评论