Close

Java 8 Streams - LongStream.noneMatch Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.LongStream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamjava.util.stream.LongStreamLongStreamLogicBig

Method:

boolean noneMatch(LongPredicate predicate)

This terminal operation returns whether no elements of this stream match the provided predicate. It may not evaluate the predicate on all elements if not necessary for determining the result, hence, it is a short circuiting operation. If the stream is empty then true is returned and the predicate is not evaluated.

Examples


package com.logicbig.example.longstream;

import java.util.stream.LongStream;

public class NoneMatchExample {

public static void main(String... args) {
LongStream stream = LongStream.of(4, 7, 9, 11, 13, 17);
boolean b = stream.noneMatch(value -> value % 10 == 0);
System.out.println(b);

LongStream stream2 = LongStream.of(4, 7, 9, 11, 13, 17, 100);
boolean b2 = stream2.noneMatch(value -> value % 10 == 0);
System.out.println(b2);
}
}

Output

true
false




package com.logicbig.example.longstream;

import java.util.stream.LongStream;

public class NoneMatchExample2 {

public static void main(String... args) {
LongStream stream = LongStream.empty();
boolean b = stream.noneMatch(value -> false);
System.out.println(b);
}
}

Output

true




See Also