Close

Java 8 Streams - DoubleStream.allMatch Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.DoubleStream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamjava.util.stream.DoubleStreamDoubleStreamLogicBig

Method:

boolean allMatch(DoublePredicate predicate)

This terminal-short-circuiting operation returns whether all elements match the provided predicate criteria. It returns 'false' on finding the first mismatch hence short-circuiting the operation.

If the stream is empty then this method returns true and the predicate is not evaluated.

Examples


package com.logicbig.example.doublestream;

import java.util.stream.DoubleStream;

public class AllMatchExample {

public static void main(String... args) {
DoubleStream doubleStream = DoubleStream.of(1.2, 1.3, 1.4, 1.5, 1.6);
boolean b = doubleStream.allMatch(value -> value < 2.0d);
System.out.println(b);

DoubleStream doubleStream2 = DoubleStream.of(1.2, 1.3, 1.4, 1.5, 2.0001);
boolean b2 = doubleStream2.allMatch(value -> value <= 2.0d);
System.out.println(b2);
}
}

Output

true
false




package com.logicbig.example.doublestream;

import java.util.stream.DoubleStream;

public class AllMatchExample2 {

public static void main(String... args) {
DoubleStream doubleStream = DoubleStream.empty();
boolean b = doubleStream.allMatch(d -> false);
System.out.println(b);
}
}

Output

true




See Also