由于在开发过程中需要用到迭代和遍历整理出适合的集合
public static List<CmtCommentReply> replyCollections(List<CmtCommentReply> list,int replayToNum){
for(CmtCommentReply cmtCommentReplay : list){
for(CmtCommentReply cmtCR : list){
if(replayToNum == cmtCR.getFloor() && replayToNum != 0){
listFloors.add(cmtCR);
replayToNum = cmtCR.getReplyTo();
list.remove(cmtCR);
replyCollections(list,replayToNum);
}else{
continue;
}
}
}
return listFloors;
}
Exception in thread "main" java.util.ConcurrentModificationException
解决方法:
1.for循环改用索引遍历
2.使用并发容器CopyOnWriteArrayList代替ArrayList和Vector
如下图