Lambdas and streams on one page
Java 8 added lambda expressions and the Stream API, and they are still the core of everyday Java code. This cheat sheet explains the syntax, shows which functional interface a lambda maps to, and draws what every common stream operation does to its input.
What's on the Java 8 cheat sheet
Lambda expressions
- The two lambda forms:
(params) -> expressionand(params) -> { statements; } - An annotated
Comparatorexample: functional method, parameter list and implementation - Lambda examples: no parameters, typed and inferred parameters, expression and block bodies, and when the parentheses are optional
Functional interfaces
The method signatures of Predicate, Supplier, Consumer, Function, BiPredicate, BiConsumer, BiFunction and BinaryOperator.
Stream API
How a pipeline is built from a source, lazy intermediate operations and one terminal operation, using a people.stream() example with method references. Each operation is drawn as input → output:
- Intermediate:
map,flatMap,filter,peek,limit,skip,distinct,sorted - Terminal:
findAny,findFirst,allMatch,noneMatch,anyMatch,count,min,max,collect,forEach,reduce
Is it still useful after Java 8?
Yes. Everything on the sheet works the same in current Java versions. Newer releases added more on top, such as var in lambda parameters and Stream.toList(), which the sheet doesn't cover.