Iterators in Java Collections: Iterator and ListIterator
An Iterator traverses a collection without exposing its structure. See safe removal, fail-fast rules, ListIterator and a custom Iterable.
2,889 posts about Java: questions with answers, tutorials and articles, newest first.
An Iterator traverses a collection without exposing its structure. See safe removal, fail-fast rules, ListIterator and a custom Iterable.
HashMap offers fast unordered lookups, while TreeMap keeps keys sorted and supports range queries. Compare speed, nulls and use cases with examples.
Use java.util.HashMap correctly, see how buckets, load factor and treeification work, and build a simple chained hash map yourself.
Java LinkedList is a doubly linked list and Deque with O(1) end operations but O(n) indexed access. See the trade-offs against ArrayList and ArrayDeque.
ArrayList is Java's resizable array list. See how it works internally, its time complexity, advantages and pitfalls such as thread safety.
Compare ArrayList, LinkedList, Vector, Stack, List.of, and CopyOnWriteArrayList, with their time costs and when each List implementation is the right choice.
List keeps ordered elements with duplicates, Set keeps unique elements, and Map stores key-value pairs. See how to choose and which implementation fits.
Overview of the Java Collections Framework: List, Set, Queue and Map interfaces, how to pick implementations, and how to use them safely.
Solve producer-consumer with a bounded BlockingQueue, then see the wait/notifyAll and ReentrantLock versions that show how it works inside.
Semaphore caps concurrent access to a shared resource with permits. See acquire and release, tryAcquire, fair mode and when to use it instead of a lock.
CyclicBarrier makes a fixed group of Java threads wait for each other and then continue together, round after round. Includes a runnable example.
CountDownLatch is a single-use Java synchronizer that makes threads wait until a count reaches zero. See how it works, with examples and alternatives.
Build thread pools in Java with Executors and ThreadPoolExecutor, size queues and rejection policies, shut them down correctly and know when to use virtual threads.
The Executor framework runs tasks on managed thread pools instead of raw threads. See ExecutorService, Callable, Future, scheduling and virtual threads in action.
Callable is a Java interface for tasks that return a value and may throw checked exceptions, submitted to an ExecutorService and read through a Future.
Thread.join() blocks the caller until another thread ends and makes its writes visible. Learn usage, timeouts and modern alternatives in Java.
Java threads coordinate through wait(), notify() and notifyAll() on a shared monitor. See a correct producer-consumer example and the safer java.util.concurrent options.
A daemon thread runs in the background and does not keep the JVM alive. See how to create one, how virtual threads relate, and when to avoid daemons.
Java thread priorities are scheduling hints from 1 to 10. Learn defaults, platform differences, pitfalls and better alternatives like priority queues.
Thread.sleep() pauses the calling thread for at least a given time and keeps its locks. Learn how to use it safely and when to choose better alternatives.