java.util.ConcurrentModificationException异常解决办法

List<TeamMessage> tms = pmspb.getQueryList();
List<TeamMessage> temp = new ArrayList<TeamMessage>();
for (TeamMessage tm : tms) {
	if (teamReviewLogService.checkProfess(tm, user)) {
		temp.add(tm);
	}
}
// 解决java.util.ConcurrentModificationException异常
tms.removeAll(temp);

 从循环中remove不能直接remove掉元素,而是应该将需要remove掉的元素放到临时集合里面,

在循环外部remove。

猜你喜欢

转载自yuxinglab.iteye.com/blog/2082805