How to use AllMatch in IntStream?

Here is an example to explain how to use AllMatch(IntPredicate predicate) in IntStream.

Syntax:

Modifier and Type         Method
boolean                   allMatch(IntPredicate predicate)
package com.nourit.java8.Streams.IntStream;

import java.util.stream.IntStream;

public class IntStreamAllMatch {

  public static void main(String[] args) {
    System.out.println("---------- First Example -----------------");
    IntStream i = IntStream.of(6, 5, 7, 1, 2, 3, 4);
    //true if all numbers are greater than 0
    boolean d1 = i.allMatch(n -> n > 0);
    System.out.println(d1);
    System.out.println("---------- Second Example -----------------");
    
    boolean d2 = IntStream.of(6, 2, 8, 4).allMatch(k -> k % 2 == 0);  
    System.out.println(d2);
    System.out.println("----------------------------------------");
  }
}

Output:

---------- First Example -----------------
true
---------- Second Example -----------------
true
----------------------------------------

 

NOUR-IT

IT Training Center for Java and Web technology. If you enjoy and like our tutorials and believe in our mission, Please Subscribe us on Youtube and follow us on Twitter, or befriend us on Facebook or Google Plus.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

*