Java.util.function.LongPredicate interface in Java with Examples

JDK 8 introduces the IntPredicate interface. The package java.util.function contains this interface. It works with an integer value and, given a condition, returns a predicate value. It can also be utilized in lambda expression since it is a functional interface.

The Methods are given by:

1. test(): A boolean value indicating the result is returned by this function after it has evaluated a conditional check on the int value.

Syntax:

2. and(): This function creates a new object by applying the AND operation to the object that is currently in use and the object that was passed in as an argument. There is a default implementation for this method.

Syntax:

3. negate(): This function reverses the test condition and returns the inverse of the current predicate. There is a default implementation for this method.

Syntax:

4. or(): After applying the OR operation on the object that is currently in use and the object that was given as an input, this function returns the newly created object. There is a default implementation for this method.

Syntax:

Example 1:

The given Java program shows how to find out if an integer is even by using the IntPredicate functional interface.

Implementation:

FileName: IntPredicateSamll.java

Output:

Is 4 even or not : true
Is 9 even or not : false

Example 2:

The given Java program shows how to execute multiple operations on integers using the IntPredicate functional interface.

Implementation:

FileName: IntPredicate.java

Output:

655441 is less than 655441 true
655441 is equal to 655441 true
655441 is less than equal to 655441 true
655441 is equal to 655441 true
655441 is greater than 655441 false