Java 8 Streams Java Java API
Interface:
java.util.stream.LongStream
Method:
boolean allMatch(LongPredicate 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.longstream;
import java.util.stream.LongStream;
public class AllMatchExample {
public static void main(String... args) { LongStream stream = LongStream.of(3, 6, 9); boolean b = stream.allMatch(AllMatchExample::odd); System.out.println(b);
LongStream stream2 = LongStream.of(3, 6, 14); boolean b2 = stream2.allMatch(AllMatchExample::odd); System.out.println(b2); }
private static boolean odd(long lg) { return lg % 3 == 0; } }
Outputtrue false
package com.logicbig.example.longstream;
import java.util.stream.LongStream;
public class AllMatchExample2 {
public static void main(String... args) { LongStream stream = LongStream.empty(); boolean b = stream.allMatch(lg -> false); System.out.println(b); } }
Outputtrue
|