目的是從createdList裏面找到匹配的pendingStatusList,並將其從pendingStatusList中remove java
for (DocSyncStatus pendingDss : pendingStatusList) { for (DocSyncStatus createdDss : createdList) { if (pendingDss.getDocHash().equals(createdDss.getDocHash())) { // add into the res list to delete them from the DB. successDocStatusRes.add(pendingDss); Log.i(TAG, "find the pending doc in the docsync cloud server by syncDoc,pendingDss=" + pendingDss); pendingStatusList.remove(pendingDss); } } }
從http://blog.csdn.net/aa4790139/article/details/6438869這裏找到了緣由,並改成以下版本: spa
for (Iterator it = pendingStatusList.iterator(); it.hasNext();) { DocSyncStatus pendingDss = (DocSyncStatus) it.next(); for (DocSyncStatus createdDss : createdList) { if (pendingDss.getDocHash().equals(createdDss.getDocHash())) { // add into the res list to delete them from the DB. successDocStatusRes.add(pendingDss); Log.i(TAG, "find the pending doc in the docsync cloud server by syncDoc,pendingDss=" + pendingDss); it.remove(); } } }
從http://stackoverflow.com/questions/13539716/java-error-when-removing-from-an-arraylist-more-than-once-illegalstateexcept 這裏找到了解決方案: .net
for (Iterator<DocSyncStatus> it = pendingStatusList.iterator(); it.hasNext();) { DocSyncStatus pendingDss = (DocSyncStatus) it.next(); for (DocSyncStatus createdDss : createdList) { if (pendingDss.getDocHash().equals(createdDss.getDocHash())) { // add into the res list to delete them from the DB. successDocStatusRes.add(pendingDss); Log.i(TAG, "find the pending doc in the docsync cloud server by syncDoc,pendingDss=" + pendingDss); it.remove(); } } }