What Is the Stream Interface in Java? Pipelines and Examples
The Java Stream interface processes element sequences with lazy, declarative pipelines. Learn operations, parallel use, and newer additions like toList.
2,887 posts about Java: questions with answers, tutorials and articles, newest first.
The Java Stream interface processes element sequences with lazy, declarative pipelines. Learn operations, parallel use, and newer additions like toList.
Reverse a Java list in place with Collections.reverse or get a view with reversed() on Java 21. Compares copies, iterators and immutable-list pitfalls.
Use the Deque interface with ArrayDeque for most cases. Learn the operations at both ends, stack and queue usage, thread-safe variants and a custom implementation.
PriorityQueue is a heap-based queue in java.util that always returns the least element first, by natural order or a Comparator.
ListIterator extends Iterator with backward traversal, indexes and in-place add, set and remove for lists. Learn the cursor model and see runnable examples.
Build Java comparators with Comparator.comparing and thenComparing, handle nulls and locales, and sort lists, arrays, streams and maps correctly.
Comparator lets you sort Java objects by any rule. See how compare works, how to chain comparators, handle nulls, and how it differs from Comparable.
Learn how Java's LinkedHashMap preserves insertion or access order, how to build an LRU cache, and which Java 21 sequenced methods it adds.
SortedMap keeps keys in order, and NavigableMap adds floor, ceiling and descending views. See how TreeMap and ConcurrentSkipListMap use them.
HashMap is fast and allows nulls; Hashtable is a synchronised legacy class. Learn the differences and why ConcurrentHashMap is usually better.
Learn how to create and use a Java HashMap: add, read, update and remove entries, iterate safely, use custom keys, and compare Map types.
Learn what the Java Map interface is, its core methods, and how to choose between HashMap, LinkedHashMap, TreeMap and ConcurrentHashMap.
LinkedHashSet stores unique elements and iterates them in insertion order. See constructors, Java 21 sequenced methods and when to prefer it over HashSet.
TreeSet stores unique elements in sorted order with O(log n) operations. See custom comparators, navigation methods and when to prefer HashSet.
HashSet stores unique elements in a hash table with fast lookups and no ordering. Learn its features, internals, equals and hashCode rules and alternatives.
A List keeps order and duplicates and supports index access, while a Set stores unique elements. Compare their implementations, performance and Java 21 sequenced collections.
Learn how CyclicBarrier lets a fixed group of threads meet at a barrier, run a barrier action and repeat, with a full example and failure handling.
CountDownLatch makes one or more threads wait until a fixed number of tasks complete. See how countDown and await work, with examples, pitfalls and alternatives.
Use ReentrantReadWriteLock so many threads can read at once while writes stay exclusive. Includes a cache example, downgrading, fairness and alternatives.
Learn what ReentrantLock is, how it differs from synchronized, and how to use tryLock, fairness and Conditions safely with a complete tested example.