ArchitectMind
  1. Home
  2. Java Ecosystem
  3. Book 1 · Core Java & Modern Java
  4. Volume II
  5. Iterator
Book 1 · Volume II — Generics, Collections & Type System · Topic 6.1

Iterator

The Iterator interface and fail-fast behaviour

13 min readStage 1 · Foundations14 interview questions
Prerequisites
4.1 Collection Architecture · 5.2 ArrayList Internals (modCount)
Covers
Iterator interface · Fail-fast behavior
Related
6.2 Iterable · 6.3 Spliterator · B2V4 (weakly consistent iterators)
On this page
  1. 1. Concept / Definition
  2. 2. Why It Exists
  3. 3. Core Concepts
  4. 4. How It Works Internally
  5. 5. APIs / Features / Syntax
  6. 6. Practical Examples
  7. 7. Common Problems & Mistakes
  8. 8. Performance & Production Considerations
  9. 9. Architecture & Design Considerations
  10. 10. Interview Questions & Answers
  11. Key Takeaways

1Concept / Definition

An Iterator traverses a collection one element at a time without exposing how the collection is stored. It is the common traversal mechanism behind for-each loops, forEach, and most collection algorithms. Iterators of the standard java.util collections are fail-fast: they detect structural modification made outside the iterator and throw ConcurrentModificationException rather than continue with inconsistent state.

An iterator is a cursor that moves past elements
Figure 1 — An iterator is a cursor that moves past elements

2Why It Exists

Every collection stores its elements differently: an ArrayList in an array, a LinkedList in linked nodes, a HashMap in buckets, a TreeMap in a red-black tree. Code that walks a collection should not have to know which one it has. Before Java 1.2, Vector and Hashtable offered Enumeration for this, with long method names and no way to remove an element during the walk. The collections framework replaced it with Iterator: the same two-step protocol, hasNext() and next(), plus remove().

The iterator is also where the framework protects its own consistency. A loop that holds an index or a node pointer while someone else changes the structure can skip elements, visit one twice or read a slot that no longer exists. Fail-fast iterators turn most of those silent errors into an immediate ConcurrentModificationException, close to the code that caused them. For-each loops, forEach, removeIf, addAll and most of the algorithms of topic 6.4 are built on this one interface.

3Core Concepts

Iterator interface

Iterator<E> has three methods: hasNext(), next() and the optional remove(), plus the default forEachRemaining(Consumer). next() throws NoSuchElementException past the end. remove() deletes the element most recently returned by next() and may be called only once per next(); it throws UnsupportedOperationException for read-only collections. ListIterator extends it for lists with bidirectional movement (previous), indexes, set and add.

Fail-fast behavior

Collections such as ArrayList and HashMap keep a modCount that increments on every structural modification (add, remove, clear — not set). An iterator records the value when created and checks it on each next(); a mismatch means the collection changed behind its back, and it throws ConcurrentModificationException (CME). Removal through the iterator's own remove() updates both counts, so it is safe.

How fail-fast detection works
Figure 2 — How fail-fast detection works

Despite its name, CME is usually caused by a single thread modifying a collection inside its own loop. Fail-fast checking is also best-effort: it is not synchronised, so it cannot be relied on to detect real concurrent modification by other threads, which may instead corrupt data silently. Concurrent collections (ConcurrentHashMap, CopyOnWriteArrayList) provide weakly consistent or snapshot iterators that never throw CME.

Safe ways to remove elements during iteration
Figure 3 — Safe ways to remove elements during iteration

4How It Works Internally

ArrayList's iterator is a small inner class with three fields. cursor is the index of the element that the next call to next() returns, lastRet is the index of the element returned last (or -1), and expectedModCount is a copy of the list's modCount taken when the iterator was created. next() first compares the two counters, then reads the element at cursor and moves on. remove() throws IllegalStateException when lastRet is -1, removes the element at lastRet through the list, moves cursor back to it and copies the new modCount into expectedModCount, which is why removing through the iterator is safe (Figure 4).

ArrayList's iterator compares modCount with its own copy on every next()
Figure 4 — ArrayList's iterator compares modCount with its own copy on every next()

hasNext() performs no check at all: it only returns cursor != size. That detail explains the odd case listed in section 7. When the loop body removes the second-to-last element, the size drops to the value of the cursor, hasNext() returns false and the loop ends without an exception and without visiting the last element (Figure 5). Removing any other element leaves hasNext() true, and the following next() throws.

After the second-to-last element is removed, hasNext() returns false
Figure 5 — After the second-to-last element is removed, hasNext() returns false

Other collections follow the same pattern. HashMap's iterators keep a reference to the next node and a copy of modCount; LinkedList's iterator keeps the next node and an index. Bulk methods check once instead of per element: ArrayList.forEach and forEachRemaining run the whole loop and then throw if modCount changed, and ArrayList.removeIf marks the elements to delete first and compacts the array in one pass. None of the counters are volatile or synchronised, so another thread's change may simply not be seen: that is why fail-fast detection is described as best-effort.

5APIs / Features / Syntax

The iteration API is spread over four interfaces. The methods worth knowing, with the version that added each:

MethodWhat it doesNotes
Iterator.hasNext() / next()Test for and return the next elementnext() past the end: NoSuchElementException
Iterator.remove()Remove the element last returned by next()Optional; once per next(); IllegalStateException otherwise
Iterator.forEachRemaining(action)Run action on every remaining elementJava 8; checks modCount once, at the end
ListIterator.previous() / hasPrevious()Move backwards through a listlistIterator(n) starts at index n
ListIterator.set(e) / add(e)Replace the last returned element / insert at the cursorset() is not allowed straight after add() or remove()
Collection.removeIf(predicate)Remove every matching elementJava 8; the usual replacement for an explicit iterator loop
Map.replaceAll(fn), Map.Entry.setValue(v)Change values while walking a mapNon-structural: no CME

Enumeration, returned by Vector.elements() and a few older APIs, is still supported. Since Java 9 Enumeration.asIterator() adapts it, so legacy sources can be used with the same loop code.

6Practical Examples

Example 1 — Safe removal, map updates and a custom iterator

Problem. A clean-up job removes expired orders, decrements stock counts and deletes the entries that reach zero, and a reporting helper needs a numeric range that works in a for-each loop.

JAVAIterator usage and implementation
// Safe removal
Iterator<Order> it = orders.iterator();
while (it.hasNext()) {
    if (it.next().isExpired()) it.remove();
}
orders.removeIf(Order::isExpired);                     // preferred, clearer

// Map entries: remove or update during iteration
for (Iterator<Map.Entry<String, Integer>> e = stock.entrySet().iterator(); e.hasNext(); ) {
    Map.Entry<String, Integer> entry = e.next();
    if (entry.getValue() == 0) e.remove();
    else entry.setValue(entry.getValue() - 1);  // non-structural: allowed
}

// A custom iterator
public final class Range implements Iterable<Integer> {
    private final int from, to;
    public Range(int from, int to) { this.from = from; this.to = to; }
    public Iterator<Integer> iterator() {
        return new Iterator<>() {
            int next = from;
            public boolean hasNext() { return next < to; }
            public Integer next() {
                if (!hasNext()) throw new NoSuchElementException();
                return next++;
            }
        };
    }
}

Why it works. Both removals go through the iterator, so its expected count stays in step with the collection; removeIf does the same in one call. entry.setValue replaces a value without changing the map's structure, so it does not increment modCount. Range stores no elements at all: each call to iterator() returns a fresh cursor, and next() honours the contract by throwing NoSuchElementException at the end.

Example 2 — Mini program: removing during iteration, every way side by side

Problem. Section 7 lists the ways of removing elements while a loop runs. This program runs each of them on a small list, so the results can be compared: the exception, the silent skip, and the three safe forms.

JAVAFailFastLab.java
public class FailFastLab {
    public static void main(String[] args) {
        // 1. collection.remove inside for-each: the next next() fails
        List<String> a = new ArrayList<>(List.of("a", "b", "c", "d"));
        try {
            for (String s : a) if (s.equals("b")) a.remove(s);
        } catch (ConcurrentModificationException e) {
            System.out.println("1. remove(b) in for-each: "
                    + e.getClass().getSimpleName());
        }
        // 2. the second-to-last element: no exception, "d" is never visited
        List<String> b = new ArrayList<>(List.of("a", "b", "c", "d"));
        List<String> seen = new ArrayList<>();
        for (String s : b) {
            seen.add(s);
            if (s.equals("c")) b.remove(s);
        }
        System.out.println("2. remove(c) in for-each: seen " + seen
                + ", list " + b);
        // 3. Iterator.remove: the iterator resynchronises its expected count
        List<String> c = new ArrayList<>(List.of("a", "b", "c", "d"));
        for (Iterator<String> it = c.iterator(); it.hasNext(); )
            if (it.next().compareTo("b") <= 0) it.remove();
        System.out.println("3. iterator.remove: " + c);
        // 4. removeIf: one call, no iterator in the caller's code
        List<Integer> qty = new ArrayList<>(List.of(5, 0, 3, 0, 7));
        qty.removeIf(q -> q == 0);
        System.out.println("4. removeIf: " + qty);
        // 5. ListIterator: replace and insert while walking
        List<String> d = new ArrayList<>(List.of("x", "y", "z"));
        for (ListIterator<String> li = d.listIterator(); li.hasNext(); ) {
            if (li.next().equals("y")) { li.set("Y"); li.add("y2"); }
        }
        System.out.println("5. listIterator set + add: " + d);
        // 6. remove() twice for one next()
        Iterator<String> it = d.iterator();
        it.next(); it.remove();
        try {
            it.remove();
        } catch (IllegalStateException e) {
            System.out.println("6. second remove(): IllegalStateException");
        }
    }
}
OUTPUT
1. remove(b) in for-each: ConcurrentModificationException
2. remove(c) in for-each: seen [a, b, c], list [a, b, d]
3. iterator.remove: [c, d]
4. removeIf: [5, 3, 7]
5. listIterator set + add: [x, Y, y2, z]
6. second remove(): IllegalStateException

Why it behaves this way. In case 1 the list shrinks to three elements while the cursor is at 2, so hasNext() is true and the next next() finds modCount changed. Case 2 removes the second-to-last element: the size becomes equal to the cursor and the loop simply stops, so "d" is never seen (Figure 5). Cases 3 to 5 change the list through the iterator or through removeIf, which keep the counters in step. ListIterator.add inserts before the cursor, so the loop continues with "z" and does not visit "y2". Case 6 shows that remove() is allowed once per next().

Example 3 — A listener that unregisters itself during notification

Problem. An in-process event bus keeps its listeners in a list. A one-shot listener removes itself when it receives the first event. Section 8 says this is the classic source of production CMEs; the program shows that it can be worse than an exception.

JAVAListenerRegistry.java
public class ListenerRegistry {
    static void run(String name, List<Consumer<String>> listeners, int pos) {
        List<String> log = new ArrayList<>();
        Consumer<String> once = new Consumer<>() {          // one-shot listener
            public void accept(String e) {
                log.add("once:" + e);
                listeners.remove(this);
            }
        };
        listeners.add(e -> log.add("audit:" + e));
        listeners.add(e -> log.add("metrics:" + e));
        listeners.add(pos, once);
        try {
            for (String event : List.of("e1", "e2"))
                for (Consumer<String> l : listeners) l.accept(event);
            System.out.println(name + " once at " + pos + ": " + log);
        } catch (ConcurrentModificationException ex) {
            System.out.println(name + " once at " + pos + ": CME after "
                    + log);
        }
    }
 
    public static void main(String[] args) {
        run("ArrayList", new ArrayList<>(), 0);
        run("ArrayList", new ArrayList<>(), 1);
        run("CopyOnWrite", new CopyOnWriteArrayList<>(), 0);
        run("CopyOnWrite", new CopyOnWriteArrayList<>(), 1);
    }
}
OUTPUT
ArrayList once at 0: CME after [once:e1]
ArrayList once at 1: [audit:e1, once:e1, audit:e2, metrics:e2]
CopyOnWrite once at 0: [once:e1, audit:e1, metrics:e1, audit:e2, metrics:e2]
CopyOnWrite once at 1: [audit:e1, once:e1, metrics:e1, audit:e2, metrics:e2]

Why it behaves this way. With an ArrayList, the outcome depends on where the one-shot listener sits. First in the list, its removal makes the next next() throw. Second of three, it is the second-to-last element, so the loop ends early and the metrics listener silently misses event e1. CopyOnWriteArrayList copies its array on every change, and its iterators walk the array that existed when they were created, so every listener receives every event and the one-shot listener is gone from the second event on.

Example 4 — A custom collection with its own fail-fast iterator

Problem. A service keeps the last few requests in a fixed-size ring buffer for diagnostics. Extending AbstractCollection gives it contains, toString, removeIf and the rest for free, but only if its iterator follows the contract of section 4.

JAVARingBuffer.java
public class RingBuffer<E> extends AbstractCollection<E> {
    private final Object[] items;
    private int head, size, modCount;
 
    public RingBuffer(int capacity) { items = new Object[capacity]; }
    private int slot(int i) { return (head + i) % items.length; }
 
    @Override public boolean add(E e) {     // full: overwrite the oldest
        items[slot(size)] = e;
        if (size == items.length) head = slot(1); else size++;
        modCount++;
        return true;
    }
    @Override public int size() { return size; }
 
    @Override public Iterator<E> iterator() {
        return new Iterator<>() {
            int next = 0, last = -1, expected = modCount;
            public boolean hasNext() { return next < size; }
            @SuppressWarnings("unchecked") public E next() {
                check();
                if (next >= size) throw new NoSuchElementException();
                last = next;
                return (E) items[slot(next++)];
            }
            public void remove() {
                if (last < 0) throw new IllegalStateException();
                check();
                for (int i = last; i < size - 1; i++)
                    items[slot(i)] = items[slot(i + 1)];
                items[slot(--size)] = null;
                next = last; last = -1;
                expected = ++modCount;           // our own change: resync
            }
            private void check() {
                if (modCount != expected)
                    throw new ConcurrentModificationException();
            }
        };
    }
 
    public static void main(String[] args) {
        RingBuffer<String> recent = new RingBuffer<>(3);
        for (String s : List.of("a", "b", "c", "d")) recent.add(s);
        System.out.println("after 4 adds: " + recent);
        recent.removeIf(s -> s.equals("c"));   // default removeIf -> remove()
        System.out.println("after removeIf: " + recent);
        try {
            for (String s : recent) recent.add(s + "!");
        } catch (ConcurrentModificationException e) {
            System.out.println("add inside for-each: CME");
        }
        System.out.println("now: " + recent);
    }
}
OUTPUT
after 4 adds: [b, c, d]
after removeIf: [b, d]
add inside for-each: CME
now: [b, d, b!]

Why it behaves this way. The buffer counts its own structural changes in modCount, and the iterator compares that count with its copy in next() and remove(). removeIf is a default method of Collection that walks the iterator and calls remove(), which closes the gap and resynchronises expected, so it works without any extra code. The add inside the for-each loop is a change from outside the iterator, so the second next() throws, after the first new element was already added.

7Common Problems & Mistakes

MistakeConsequenceBetter approach
Calling collection.remove inside a for-each loopConcurrentModificationException on the next element; for the second-to-last element of an ArrayList, the loop ends early and the last element is skipped silently (Example 2)Use it.remove() or removeIf, or collect the elements and remove them after the loop
Calling it.remove() twice, or before next()IllegalStateException: remove() deletes the element last returned, and there is noneCall next() exactly once before each remove()
Relying on CME to detect multi-threaded modificationThe check is not synchronised; another thread's change may go unnoticed and corrupt data insteadUse a concurrent collection or guard every access with one lock
Custom iterators whose next() does not throw NoSuchElementException at the endCallers that rely on the contract read stale or null values, or loop foreverThrow NoSuchElementException when hasNext() is false (Example 4)
Iterating a synchronised wrapper without holding its lockEach call is synchronised, the whole loop is not; another thread can change the list between callsWrap the loop in synchronized (list) { ... }, or use a concurrent collection
Mutating a listener list while notifying listenersCME, or listeners that silently miss events (Example 3)CopyOnWriteArrayList, or iterate over a copy
Catching ConcurrentModificationException and continuing or retryingThe state is already inconsistent; a retry can process elements twiceFix the code path that modifies the collection during the loop

8Performance & Production Considerations

A CME in production usually means a collection is shared where it should not be — either modified inside a callback while being iterated (listener lists, event handlers), or accessed by several threads. The first is fixed by collecting changes and applying them after the loop, or by removeIf; the second needs a thread-safe design. CopyOnWriteArrayList is the standard remedy for listener lists that change during notification.

9Architecture & Design Considerations

A ConcurrentModificationException is a design signal more than a bug to be patched: it says that two pieces of code share one mutable collection without agreeing who may change it and when. The robust fixes are structural. Make one owner responsible for changes, publish immutable snapshots to everyone else (Chapter 7), or choose a collection whose iteration guarantee matches the use: snapshot iterators (CopyOnWriteArrayList) when reads far outnumber writes, weakly consistent iterators (ConcurrentHashMap) when both are frequent.

The same choice appears in API design. Returning an Iterator or a live view hands callers a cursor into your internal state, with all the rules of this topic; returning an immutable copy or a Stream keeps those rules inside the class. When a custom collection is unavoidable, extend AbstractCollection or AbstractList and implement the iterator contract fully, including fail-fast behaviour, so that every library method built on iteration works with it (Example 4).

10Interview Questions & Answers

Q1L1 · BasicConcept

What methods does the Iterator interface define?

hasNext(), next(), the optional remove(), and the default forEachRemaining(Consumer).

Q2L2 · IntermediateConcept

What is a fail-fast iterator?

An iterator that throws ConcurrentModificationException as soon as it detects that the collection was structurally modified other than through the iterator itself, using a modification counter.

Q3L2 · IntermediateConcept

How can you remove elements safely while iterating?

Use Iterator.remove(), Collection.removeIf, or collect elements to remove and remove them after the loop. ListIterator also allows set and add during iteration.

Q4L3 · Senior EngineerTricky

Can ConcurrentModificationException occur in single-threaded code?

Yes, and that is its most common cause: modifying a collection inside a loop that is iterating over it, for example removing in a for-each loop or a callback that modifies the list being notified.

Q5L3 · Senior EngineerInternals

What is the difference between fail-fast and weakly consistent iterators?

Fail-fast iterators (ArrayList, HashMap) throw CME on detected modification and are best-effort only. Weakly consistent iterators (ConcurrentHashMap, ConcurrentLinkedQueue) never throw CME, tolerate concurrent modification, and may or may not reflect changes made after they were created. CopyOnWriteArrayList iterators work on a snapshot.

Q6L4 · Technical ArchitectScenario

A listener framework occasionally throws CME when a listener unregisters itself during an event. How do you fix it?

Iteration and modification of the listener list overlap. Use a CopyOnWriteArrayList, whose snapshot iterators allow listeners to add or remove themselves during notification, or iterate over a copy. For heavy churn, use a concurrent set with weakly consistent iteration.

Q7L2 · IntermediateCode

What does this program print?

JAVASkipQuiz.java
public class SkipQuiz {
    public static void main(String[] args) {
        List<Integer> ids = new ArrayList<>(List.of(10, 20, 30, 40));
        int visited = 0;
        for (Integer id : ids) {
            visited++;
            if (id == 30) ids.remove(id);
        }
        System.out.println(visited + " " + ids);
    }
}

It prints 3 [10, 20, 40], with no exception. ids.remove(id) passes an Integer, so it calls remove(Object) and deletes the value 30, not the element at index 30. 30 is the second-to-last element, so after the removal the size equals the cursor, hasNext() returns false and 40 is never visited. Removing 10 or 20 instead would throw ConcurrentModificationException.

Q8L3 · Senior EngineerInternals

Which fields does ArrayList's iterator keep, and where does it check for modification?

cursor, the index of the next element; lastRet, the index of the element last returned or -1; and expectedModCount, the list's modCount when the iterator was created. next() and remove() compare the two counters and throw ConcurrentModificationException when they differ; hasNext() only compares cursor with the size. remove() deletes through the list and then copies the new modCount, so the iterator stays valid (Figure 4).

Q9L3 · Senior EngineerCode

What does this program print?

JAVAListIterQuiz.java
public class ListIterQuiz {
    public static void main(String[] args) {
        List<String> xs = new ArrayList<>(List.of("a", "b", "c"));
        ListIterator<String> it = xs.listIterator();
        while (it.hasNext()) {
            String s = it.next();
            if (s.equals("a")) it.add("a2");
            if (s.equals("b")) it.set("B");
        }
        while (it.hasPrevious()) System.out.print(it.previous() + " ");
        System.out.println(xs);
    }
}

It prints c B a2 a [a, a2, B, c]. add("a2") inserts at the cursor, after "a", and moves the cursor past the new element, so the next call returns "b", which set replaces with "B". At the end the cursor is after "c", and previous() walks back over all four elements, including the one inserted.

Q10L3 · Senior EngineerTricky

Inside a for-each loop over map.keySet(), is map.put(k, v) always a mistake?

JAVAMapPutCheck.java
public class MapPutCheck {
    public static void main(String[] args) {
        Map<String, Integer> m = new HashMap<>(Map.of("a", 1, "b", 2, "c", 3));
        for (String k : m.keySet()) m.put(k, m.get(k) * 10);
        System.out.println("existing keys: " + new TreeMap<>(m));
        try {
            for (String k : m.keySet()) m.put(k + "2", 0);
        } catch (ConcurrentModificationException e) {
            System.out.println("new key: ConcurrentModificationException");
        }
    }
}
OUTPUT
existing keys: {a=10, b=20, c=30}
new key: ConcurrentModificationException

No. put for a key that is already present only replaces the value: it is not a structural change and does not increment modCount, so the first loop is legal. put with a new key adds an entry, and the iterator fails on its next step. Code that relies on the difference is fragile, because one new key in the data turns it into a failure; map.replaceAll((k, v) -> v * 10) states the intent and is always safe.

Q11L3 · Senior EngineerScenario

A nightly job that cleans a shared HashMap cache occasionally fails with ConcurrentModificationException, and on other nights some entries are never removed. Request threads add entries all the time. What is happening, and how do you fix it?

Two threads use a non-thread-safe map: the cleaner iterates while request threads add entries. When the cleaner happens to see the changed modCount it throws; when it does not, entries can be missed and the map itself can be damaged, because HashMap is not safe for concurrent writes. Catching the exception would hide the race, not fix it. Replace the map with a ConcurrentHashMap and clean it with map.entrySet().removeIf(e -> e.getValue().isExpired()), whose weakly consistent iterator tolerates concurrent updates; better still, use a cache library with expiry built in.

Q12L4 · Technical ArchitectDesign

You are writing a custom collection for a shared library. What iteration guarantees do you give, and how do you implement them?

First decide the concurrency model. A single-threaded collection should give fail-fast iterators: keep a modCount, compare it in next() and remove(), support remove() once per next() and throw NoSuchElementException at the end, as in Example 4. A collection meant for concurrent use should give snapshot or weakly consistent iterators and document which. Extend AbstractCollection or AbstractList so contains, removeIf and toString come for free, document the guarantee in the Javadoc, and test the contract with the iterator cases of Example 2.

Q13L5 · Solution ArchitectTrade-off

An event platform keeps 10,000 subscriptions in a CopyOnWriteArrayList and subscriptions now change hundreds of times a second. What are the alternatives and their costs?

Copy-on-write makes every change copy the whole array: at 10,000 entries and hundreds of changes a second that is megabytes of garbage per second and visible GC pressure, although reads stay lock-free. ConcurrentHashMap.newKeySet() makes changes cheap and iteration weakly consistent, at the cost of ordering and of a listener possibly missing an event published while it registers. A ReadWriteLock around an ArrayList keeps order but blocks publishers during changes. A common answer is to batch changes and publish a new immutable snapshot every few milliseconds, which keeps lock-free reads and bounds the copying; choose based on measured publish and change rates.

Q14L5 · Solution ArchitectScenario

After event dispatch is moved from one thread to many, an in-process event bus built on ArrayList shows lost and duplicated notifications in production, but never a ConcurrentModificationException. Explain and redesign.

Fail-fast detection is designed for the single-threaded case. With several threads registering, unregistering and iterating, the unsynchronised modCount and size are not reliably seen across threads, so iterators skip or repeat elements without noticing, and the array can be resized under a reader. The absence of CME proves nothing. Make the listener store thread-safe (a copy-on-write list or an immutable snapshot swapped through an AtomicReference), define whether a listener registered during a dispatch receives that event, and add a concurrency test that registers and publishes from many threads at once.

Test your knowledge on this topic →Flashcards from this topic's 14 questions, filtered by level and type.

Key Takeaways

  • Iterator: hasNext, next, optional remove; ListIterator adds bidirectional movement.
  • Fail-fast iterators throw CME on external structural modification.
  • Remove with it.remove() or removeIf, never collection.remove inside for-each.
  • CME detection is best-effort; concurrent collections use weakly consistent iterators.
Free question pack

Get 100 free Core Java interview questions

Subscribe for the Book 1 question pack (PDF, every answer explained) and new tutorials once a week. No spam, unsubscribe anytime. What is in the pack?

Almost done! Check your inbox and click the confirmation link. Your download link arrives as soon as you confirm.