LongStream filter(LongPredicate predicate) example
Description
LongStream filter(LongPredicate predicate)
returns a stream consisting of the elements of this stream that match the given predicate.
This is an intermediate operation.
Syntax
filter
has the following syntax.
LongStream filter(LongPredicate predicate)
Example
The following example shows how to use filter
.
import java.util.stream.LongStream;
// ww w . j av a2 s. c o m
public class Main {
public static void main(String[] args) {
LongStream b = LongStream.of(1L, 2L, 3L, 4L);
b.filter(l -> l % 2 == 0);
b.forEach(System.out::println);
}
}