12) Lambdas & Streams
Goal
Write cleaner collection transformations and understand functional-style Java.
Lambdas
List<String> names = List.of("sam", "li", "asha");
names.forEach(n -> System.out.println(n.toUpperCase()));
Streams
List<String> names = List.of("sam", "li", "asha");
List<String> upper = names.stream()
.map(String::toUpperCase)
.sorted()
.toList();
Filtering and reducing
int sum = List.of(1, 2, 3, 4).stream()
.filter(n -> n % 2 == 0)
.mapToInt(n -> n)
.sum();
Exercises
- Given a list of words, return only those with length >= 5 (uppercase).
- Compute the average of numbers using streams.
- Group words by first letter using
Collectors.groupingBy.
Table of contents
- Getting Started: Install, run, and your first program
- Java Basics: types, variables, operators, formatting
- Control Flow: if/switch/loops
- Methods: parameters, return values, overloading
- OOP: classes, objects, encapsulation
- Inheritance & Polymorphism (and when not to use them)
- Interfaces, abstract classes, and design basics
- Exceptions and error handling
- Strings, files, and I/O basics
- Collections: List/Set/Map and Big-O intuition
- Generics (the useful parts)
- Lambdas & Streams
- Dates and time (java.time)
- Testing with JUnit 5 (basics)
- Concurrency: threads, executors, futures
- JVM basics: memory, GC, performance habits
- Build tools: Maven essentials (recommended)
- Next steps: projects to build