IntPredicate Interface is a part of the java.util.function package which is introduced in Java 8. It is an in-built Functional Interface. This function expects one int-valued argument as input and produces a boolean value as an output. As it is a functional interface, it can be used assignment target for a lambda expression or method reference. In this post, we are going to see several implementations of IntPredicate Interface by using different examples.

IntPredicate_Interface_Java8_Techndeck

IntPredicate Interface in Java 8 with Examples...!!! Click To Tweet

Look at IntPredicate Javadoc description below:

IntPredicateInterface_Signature_Java8_Techndeck

IntPredicate Interface contains 4 methods:

  1. test

  2. and

  3. or

  4. negate

Let’s discuss these methods:

test 

This method evaluates predicate on the given argument and produces a boolean result.

and 

This method returns a composed predicate that represents a short-circuiting logical AND of this predicate and another. When evaluating the composed predicate, if this predicate is false, then the other predicate is not evaluated.

or 

This method returns a composed predicate that represents a short-circuiting logical OR of this predicate and another. When evaluating the composed predicate, if this predicate is true, then the other predicate is not evaluated.

negate 

This method returns a predicate that represents the logical negation of this predicate.

Let’s understand above-mentioned methods through various examples:

Example 1. ‘test’ method

Example 2. ‘and’, ‘or’ and ‘negate’ methods

Java 8 IntPredicate Interface is an absolutely useful addition as part of ‘Functional Interfaces’ and can serve a variety of purposes. It is quite powerful as it can be used as a higher-order function through lambda functions and the above examples could help you to get a better idea of how to implement it.

IntPredicate Interface in Java 8 with Examples...!!! Click To Tweet

Do you like this Post? – then check my other helpful posts:

Other Useful References:

Author

  • Deepak Verma is a Test Automation Consultant and Software development Engineer for more than 10 years. His mission is to help you become an In-demand full stack automation tester. He is also the founder of Techndeck, a blog and online coaching platform dedicated to helping you succeed with all the automation basics to advanced testing automation tricks.

close

Enjoy this blog? Please spread the word :)

Follow by Email
Twitter