Lambdas and Functional Interfaces
LockedLesson 20 of 60 · Syntax · Challenging
Finish these first:Interfaces and Abstract Classes →Or pass the tests below to unlock it now.
The big idea
A lambda implements a functional interface (one abstract method): Function<T,R, Predicate<T, Supplier<T, Consumer<T.
Think of it like this: Think of syntax and expressions like labeled measuring cups in a kitchen: each cup holds a specific kind of ingredient, and operators combine them into a new measurement.
Read the lesson
A lambda implements a functional interface (one abstract method): Function<T,R>, Predicate<T>, Supplier<T>, Consumer<T>.
Predicate<String> empty = String::isEmpty;
Function<Integer,Integer> twice = x -> x * 2;
list.removeIf(x -> x < 0);
Quick check
Before writing code: What should `Solution.filter(java.util.List.of(1,2,3,4), x -> x % 2 == 0)` return when your implementation of Lambdas and Functional Interfaces is working?
Your challenge
Write static <T> List<T> filter(List<T> xs, java.util.function.Predicate<T> p).
More learning tools(compare languages, visual guide, related lessons)
Compare with another language
Similar to python.decorators (30% overlap). No direct Java equivalent; closest are higher-order functions and annotations.
Visual walkthrough
A diagram, a step-by-step animation, and short captions for Lambdas and Functional Interfaces.