Java 8 - Functional Interfaces
Java 8 - Functional Interfaces
Functional interfaces have a single functionality to exhibit. For example, a Comparable interface
with a single method ‘compareTo’ is used for comparison purpose. Java 8 has defined a lot of
functional interfaces to be used extensively in lambda expressions. Following is the list of
functional interfaces defined in java.util.Function package.
Create the following Java program using any editor of your choice in, say, C:\> JAVA.
Java8Tester.java
Live Demo
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
// test method will always return true no matter what value n has.
//pass n as parameter
eval(list, n->true);
https://www.tutorialspoint.com/java8/java8_functional_interfaces.htm 1/3
8/10/22, 8:36 PM Java 8 - Functional Interfaces
for(Integer n: list) {
if(predicate.test(n)) {
Here we've passed Predicate interface, which takes a single input and returns Boolean.
C:\JAVA>javac Java8Tester.java
C:\JAVA>java Java8Tester
https://www.tutorialspoint.com/java8/java8_functional_interfaces.htm 2/3
8/10/22, 8:36 PM Java 8 - Functional Interfaces
https://www.tutorialspoint.com/java8/java8_functional_interfaces.htm 3/3