寫法一:
Iterator<QcSampleDTO> it = qclist.iterator();
//排除尾箱容器
while (it.hasNext()) {
if(it.next().getContainerId().equals(tailDTO.getContainerId())
&& it.next().getLotId().equals(tailDTO.getLotId())) {
it.remove();
}
}
出現了兩次 it.next() ,如果list集合長度爲2,就不會第二次進入遍歷。
寫法二:
QcSampleDTO tailDTO = tailList.get(0);
Iterator<QcSampleDTO> it = qclist.iterator();
//排除尾箱容器
while (it.hasNext()) {
QcSampleDTO sampleDTO = it.next();
if (sampleDTO.getContainerId().equals(tailDTO.getContainerId())
&& sampleDTO.getLotId().equals(tailDTO.getLotId())) {
it.remove();
}
}
寫法一是個坑,it.next()使用一次,下標加一,寫法二正確。