目的是从createdList里面找到匹配的pendingStatusList,并将其从pendingStatusList中remove
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这里找到了原因,并改为如下版本:
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 这里找到了解决方案:
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();
}
}
}