Stream API — functional-style operations on collections for filtering, mapping, and reducing.
1List<String> names = List.of("Alice", "Bob", "Charlie", "David");23// Filter, map, collect4List<String> result = names.stream()5 .filter(name -> name.length() > 3)6 .map(String::toUpperCase)7 .sorted()8 .collect(Collectors.toList());9// [ALICE, CHARLIE, DAVID]1011// Reduce12int sum = IntStream.range(1, 101).reduce(0, Integer::sum);1314// Parallel15long count = names.parallelStream()16 .filter(name -> name.startsWith("A"))17 .count();1819// Collectors20Map<Integer, List<String>> grouped = names.stream()21 .collect(Collectors.groupingBy(String::length));
Key operations: