In this Q&A, we'll go over how to take from a Stream until a condition is met
IntStream is = IntStream.of(1,100)
List<Integer> l = is.takeWhile(x-> x <= 7).collect(Collectors.toList());
IntStream is = IntStream.of(1,100)
List<Integer> l = is.takeWhile(x-> x <= 7).collect(Collectors.toList());
There is no Java 8 equivalent for this function. But this StreamUtils project can be used to achieve the same
There is a similar functional dropWhile that filters all elements until a condition is met.
Comments
Post a Comment