Wednesday 20 July 2022

What is Predicate in JAVA 8 ? Mphasis Interview Question-2022

 Predicate in JAVA 8:

A predicate is a built in functional interface present in java.util.function package. It is specifically used for code management and unit testing. It contains many built in methods which is as follows:

test(T t): It evaluates the predicate on the value passed to this function as the argument and returning a boolean value(true / false).

TestExample.java

import java.util.function.Predicate; 


class TestExample

{

public static void main(String[] args)

{

Predicate<Integer> greater_than = x -> (x > 100);  

  

        // calling test method of the predicate

        System.out.println(greater_than.test(200));  

    } 



No comments:

Post a Comment