There are two reasons for this.
- Another thread updates the inventory list directly or through its iterator
- In the same stream, possibly inside this cycle, the list of stocks changes (see example below)
The codes below may throw a ConcurrentModificationException
Iterator<Stock> itr = stockList.iterator();
while(itr.hasNext())
{
Stock temp = itr.next();
stockList.add(new Stock());
stockList.remove(0)
}
source
share