Deque<Employee> employeeDeque = new LinkedList<>();
employeeDeque.offerLast(new Employee("Michael", 250));
employeeDeque.offerLast(new Employee("John", 250));
Iterator iterator = employeeDeque.iterator();
while (iterator.hasNext()) {
iterator.next();
employeeDeque.remove(new Employee("Michael", 250));
}
The same code with ArrayList with produce this exception, but remove on LinkedList doesn't. Why is it so? Add() and Offer() methods still produce it.
The Javadoc for LinkedList
says,
Note that the fail-fast behavior of an iterator cannot be guaranteed...Fail-fast iterators throw
ConcurrentModificationException
on a best-effort basis.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.