Java 9 adds four new Stream API methods. `takeWhile` returns the longest prefix of elements that pass a predicate, stopping at the first failure. `dropWhile` does the opposite, dropping elements while the predicate holds and returning the rest. A new overload of `Stream.iterate` accepts a predicate as a termination condition, enabling finite streams without `limit`. Finally, `Stream.ofNullable` creates a single-element stream or an empty stream if the value is null, simplifying null-safe stream pipelines. Each method is explained with code examples, and edge cases around ordering, concurrency, and iterator-like data structures are covered.
Sort: