Lambda Expressions (Java 8) provide a clear and concise way to implement functional interfaces. Write less code, achieve more!
// No parameters
() -> System.out.println("Hello!")
// One parameter
x -> x * x
// Multiple parameters
(x, y) -> x + y// Traditional vs Lambda
Runnable r1 = new Runnable() {
public void run() { System.out.println("Old way"); }
};
Runnable r2 = () -> System.out.println("Lambda way!");
// Collections
List<String> names = Arrays.asList("Alice", "Bob");
names.forEach(name -> System.out.println(name));
names.forEach(System.out::println); // Method reference| Interface | Method | Purpose |
|---|---|---|
| Consumer | accept(T) | Takes input, no output |
| Supplier | get() | No input, returns output |
| Function | apply(T) | Input to output |
| Predicate | test(T) | Returns boolean |
Java 8+ | Eclipse/IntelliJ IDE
Keywords: Java Lambda Functional-Programming Java8 Stream-API Functional-Interface
