Java 8 Streams Java Java API
Interface:
java.util.stream.DoubleStream
Method:
boolean anyMatch(DoublePredicate predicate)
This is a terminal-short-circuiting operation. It checks whether any elements of this DoubleStream match the provided DoublePredicate. It will terminate (short-circuiting) with a result of 'true' when the very first element matches the provided predicate.
If the stream is empty then false is returned and the predicate is not evaluated.
Examples
package com.logicbig.example.doublestream;
import java.util.stream.DoubleStream;
public class AnyMatchExample {
public static void main(String... args) { DoubleStream doubleStream = DoubleStream.of(1.2, 1.3, 1.0, 1.5, 1.6); boolean b = doubleStream.anyMatch(d -> d > 1.4 && d < 1.5); System.out.println(b);
DoubleStream doubleStream2 = DoubleStream.of(1.2, 1.3, 1.0, 1.5, 1.6); boolean b2 = doubleStream2.anyMatch(d -> d % 1 == 0);//has no fractional part System.out.println(b2);
} }
Outputfalse true
package com.logicbig.example.doublestream;
import java.util.stream.DoubleStream;
public class AnyMatchExample2 {
public static void main(String... args) { DoubleStream doubleStream = DoubleStream.empty(); boolean b = doubleStream.anyMatch(d -> true); System.out.println(b); } }
Outputfalse
|
|