我正在尝试从Set中删除一个对象,而我正在使用Iterator。在JunOffer的第二次迭代中仍然得到concurrentmodificationexception:affoffer = iterator.next();.
List<sWrapper> sWrapperList = new ArrayList<sWrapper>();
for (Offering offering : offerings) {
sWrapper wrapper = new sWrapper(offering);
Set<JunOffer> junOfferSet = wrapper.getOffering().getJunOffers();
if (junOfferSet != null) {
for (Iterator<JunOffer> iterator = junOfferSet.iterator(); iterator.hasNext(); ) {
JunOffer affoffer = iterator.next();
if (affoffer.getOfferingType() == null ) {
junOfferSet.remove(affoffer);
}
}
}
sWrapperList.add(wrapper);
}
例外:
Caused by: java.util.ConcurrentModificationException
at java.util.HashMap$HashIterator.nextEntry(HashMap.java:841)
at java.util.HashMap$KeyIterator.next(HashMap.java:877)
at org.hibernate.collection.AbstractPersistentCollection$IteratorProxy.next(AbstractPersistentCollection.java:555)
at com.myself.me.off.services.SearchService.findAndValidateOffer(SearchServiceImpl.java:2536)
请帮忙解决。
提前致谢。