连续remove,第二个remove的已经被第一个remove掉了
加continue可解决
HashMap h1 = new HashMap();
h1.put("userId", "1");
HashMap h2 = new HashMap();
h2.put("userId", "2");
List<HashMap> hashMapList = new ArrayList<>();
hashMapList.add(h1);
hashMapList.add(h2);
System.out.println("hashMapList:"+hashMapList);
List<Integer> memberIdList = new ArrayList<>();
memberIdList.add(new Integer(1));
memberIdList.add(new Integer(3));
System.out.println("memberIdList:"+memberIdList);
Set<Integer> memberSet =new HashSet(memberIdList);
Iterator<HashMap> hashMapOldIterator = hashMapList.iterator();
while (hashMapOldIterator.hasNext()) {
HashMap h = hashMapOldIterator.next();
System.out.println("aaaa:"+h.entrySet());
if (memberSet.contains( Integer.parseInt(h.get("userId").toString()))){
hashMapOldIterator.remove();
continue;
}
if (h.get("userId").toString().equals("1")){
System.out.println("bbb:"+hashMapList);
hashMapOldIterator.remove();
continue;
}
}
System.out.println("ccc:"+hashMapList);