Close

Java 8 Streams - IntStream.noneMatch Examples

Java 8 Streams Java Java API 


Interface:

java.util.stream.IntStream

java.lang.AutoCloseableAutoCloseablejava.util.stream.BaseStreamBaseStreamjava.util.stream.IntStreamIntStreamLogicBig

Method:

boolean noneMatch(IntPredicate 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.intstream;

import java.util.stream.IntStream;

public class NoneMatchExample {

public static void main(String... args) {
IntStream intStream = IntStream.iterate(1, i -> i + 5)
.limit(5);
boolean b = intStream.peek(System.out::println).noneMatch(i -> i % 3 == 0);
System.out.println(b);

IntStream intStream2 = IntStream.iterate(1, i -> i + 5)
.limit(5);
boolean b2 = intStream2.peek(System.out::println).noneMatch(i -> i % 5 == 0);
System.out.println(b2);
}
}

Output

1
6
false
1
6
11
16
21
true




See Also