GCGrowCarrer

Lambdas and Functional Interfaces

Locked

Lesson 20 of 60 · Syntax · Challenging

Finish these first:Interfaces and Abstract Classes →Or pass the tests below to unlock it now.

1

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.
Key words (tap to learn):
2

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);
3

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?

4

Your challenge

2 sample tests, 1 hidden

Write static <T> List<T> filter(List<T> xs, java.util.function.Predicate<T> p).

Stuck? Get a hint (free)
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.

Mastery0%

Learn this first

Opens up next