Browse by Topic

Popular

Latest

Latest Java Posts

Illustration of a Java list being reversed in place with elements swapping from both ends toward the middle.
Java

How to Use Collections.reverse() in Java

Reverse a Java List in place with Collections.reverse(), handle arrays and sublists, create reversed copies, and avoid UnsupportedOperationException.

JavaCollectionsListArrayList
Illustration of a Java list of unordered cards being sorted into ascending order with a comparator arrow
Java

Java Collections Sort: Comparator and Comparable

java collections sort: Learn how to sort collections in Java using Collections.sort, List.sort, Comparable, and Comparator, including custom ordering rules and common...

JavaCollectionsSortingComparator
Java Collections class utility methods illustrated with sorting and synchronization icons over a collection diagram
Java

Java Collections Class: Sorting and Synchronization

Learn how to use the java.util.Collections class for sorting, shuffling, unmodifiable views, and synchronized collections, with code examples and key trade-offs.

JavaCollectionsSortingSynchronization
Diagram illustrating a Java fail fast iterator detecting collection modification and throwing ConcurrentModificationException
Java

Java Fail Fast Iterator: Behavior and Pitfalls

Java fail-fast iterators rely on modCount to detect concurrent modification. See when ConcurrentModificationException occurs and how to avoid it with iterator.remove(), snapshots, and concurrent collections.

ConcurrentModificationExceptionmodCountIteratorFail-safe
Illustration of a Java iterator detecting a list modification and throwing ConcurrentModificationException
Java

Java ConcurrentModificationException: Causes and Fixes

Why Java throws ConcurrentModificationException during iteration, how the fail-fast iterator detects changes, and how to remove elements safely.

ConcurrentModificationExceptionJava CollectionsIteratorfail-fast
Diagram showing a forward-only arrow for Iterator and a bidirectional arrow for ListIterator over a list of elements
Java

Java Iterator vs ListIterator: When to Use Each

Understand the practical differences between Java's Iterator and ListIterator interfaces, including bidirectional traversal, index access, element replacement, and when to use each.

Java CollectionsIteratorListIteratorTraversal
A Java developer using ListIterator to safely add, set, and remove elements in a list during iteration, illustrated with a cursor and list nodes.
Java

Java ListIterator add set remove: Modifying Lists

Learn how to use Java's ListIterator add, set, and remove methods to safely modify a list during iteration, including constraints, ordering rules, and examples.

ListIteratorJava CollectionsList ModificationIterator
Diagram showing a Java ListIterator moving backward through a list with previous() method
Java

Java ListIterator.previous(): Reverse Traversal Explained

Learn how to use Java's ListIterator.previous() to traverse a List backward, including hasPrevious(), cursor and index behavior, and common pitfalls.

ListIteratorJava CollectionsReverse IterationIterator
Diagram showing bidirectional traversal and modification of a Java list using ListIterator
Java

Java ListIterator: Bidirectional Traversal and In-Place Modification

Use Java ListIterator to traverse a list in both directions, modify elements during iteration, and track cursor positions. Includes practical code examples.

JavaListIteratorCollectionsIterator
Diagram contrasting Java Iterator interface control with the enhanced for loop's simplified iteration over a collection.
Java

Java Iterator vs Enhanced For: When to Use Each

java iterator vs enhanced for: Compare Java's Iterator interface with the enhanced for loop: syntax, removal behavior, stateful iteration, allocation cost, and when ea...

Java IterationIterator InterfaceEnhanced For LoopJava Collections