Companion code for the ankurm.com post "Top 40 Java Collections Interview Questions (HashMap Internals to Fail-Fast Iterators)". Verified against JDK 25's own HashMap source (TREEIFY_THRESHOLD=8, UNTREEIFY_THRESHOLD=6, MIN_TREEIFY_CAPACITY=64), with every claim backed by a committed docs/output/*.txt transcript from a real run. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YXCrLgRKFgCh9RHKW8xaqJ
5 lines
249 B
Plaintext
5 lines
249 B
Plaintext
The fix: Iterator.remove() instead of Collection.remove() during iteration
|
|
==========================================================================
|
|
|
|
list before: [1, 2, 3, 4, 5]
|
|
list after removing all even numbers via Iterator.remove(): [1, 3, 5] |