Predefined Functional Interface in Java

Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java

Program 1

package test;

import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.function.Function;
import java.util.function.Supplier;
//class Student
//{
//     private String stname;
//
//    public String getStname() 
//    {
//        return stname;
//    }
//
//    public void setStname(String stname) 
//    {
//        this.stname = stname;
//    }
//     
//}

public class TestFunctionalInterface
{
    public static void main(String[] args) 
    {
        // 4. Type of Functional Interface  Supplier 
          Supplier<Double>getRandom=()->Math.random();
          System.out.println(getRandom.get());
        // 3. Type of Functional Interface  Function 
//        Function<Integer,String>readInt=t->t*20+"Result is";
//        System.out.println(readInt.apply(5));
//          Function<Integer,String>getInt=t->t+100+"  Output is";
//          System.out.println(getInt.apply(5));
        
        // 2. Type of Functional Interface  Consumer
//        Student S=new Student();
//        Consumer<Student> setStname=S1->S1.setStname("Rajesh Sharma");
//        setStname.accept(S);
//        System.out.println(S.getStname());
        
           // 1. Type of Functional Interface  
        //Predicate<Integer> checkPN=number->number>=0;    
        //  System.out.println(checkPN.test(-10));
//         Predicate<String>checkLength=str->str.length()>5;
//         System.out.println(checkLength.test("Indore is my city"));
          
    }
}

 

Did we exceed your expectations?
If Yes, share your valuable feedback on Google

courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *