Java Streams - LongStream anyMatch(LongPredicate predicate) example








LongStream anyMatch(LongPredicate predicate) returns whether any elements of this stream match the provided predicate.

Syntax

anyMatch has the following syntax.

boolean anyMatch(LongPredicate predicate)

Example

The following example shows how to use anyMatch.

import java.util.stream.LongStream;
// w ww .  ja v a 2s.  com
public class Main {
  public static void main(String[] args) {
    LongStream b = LongStream.of(1L, 2L, Long.MAX_VALUE, Long.MIN_VALUE);
    boolean o = b.anyMatch(n-> n > 10);
    
    System.out.println(o); 
  }
}

The code above generates the following result.