Functional

1 post in this section

Stream & Optional API Enhancements (Java 9–11)

Stream API — New Methods (Java 9) Java 9 added four new instance methods to Stream<T>. All are terminal-ish or intermediate operations that make common patterns expressible without workarounds. takeWhile(Predicate) Returns elements from the beginning of the stream as long as the predicate holds, then stops. The first element that fails the predicate (and all subsequent elements) are discarded. Stream.of(1, 2, 3, 4, 5, 1, 2) .takeWhile(n -> n < 4) .

Continue reading »