Java 8 — BiPredicate | Code Factory

@FunctionalInterface
public interface BiPredicate<T,U> {
boolean test(T t, U u);
default BiPredicate<T,U> and(BiPredicate<? super T,? super U> other) { }
default BiPredicate<T,U> negate() { }
default BiPredicate<T,U> or(BiPredicate<? super T,? super U> other) { }
}

To check the sum of 2 given integers is even or not by using BiPredicate :

package com.codeFactory.bipredicate;import java.util.function.BiPredicate;public class Test {
public static void main(String... args) {
BiPredicate<Integer, Integer> p = (a, b) -> ((a+b) % 2 == 0);
System.out.println(p.test(10, 20));
System.out.println(p.test(7, 10));
}
}
true
false

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

End to End IIOT Data Dashboard

Behavioral Design Patterns #1 Strategy Design Pattern, Observer Design Pattern

The shell stores the history of entered commands, defines how you set environment variables

Database Management System In The Ultra-Modern World.

[JAVA-2j] Building a Simple Calculator: Using Try-Catch to Gracefully Handle User Mistakes

Distance, movement, and evasion

Onion Omega as a Fan Controller

Making Piano Tiles with Unity

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Code Factory

Code Factory

More from Medium

Java libraries (Java API)

Java 14 Features

Java Virtual Machine

Cloud Storage, Java