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"));
}
}