Java Streams API Cheatsheet
Quick reference for Java Streams: creation, intermediate operations, terminal operations, and collector utilities.
| Item | Description | Example | Category |
|---|---|---|---|
| stream() | Create sequential stream from collection | List<String> list = ...; Stream<String> s = list.stream(); | Creation |
| parallelStream() | Create parallel stream | Stream<String> s = list.parallelStream(); | Creation |
| Stream.of() | Create stream from values | Stream<Integer> s = Stream.of(1,2,3); | Creation |
| Arrays.stream() | Create stream from array | Stream<String> s = Arrays.stream(arr); | Creation |
| IntStream.range() | Create int stream for range | IntStream.range(1,5).forEach(System.out::println); | Creation |
| filter() | Filter elements by predicate | list.stream().filter(s -> s.startsWith("A")); | Intermediate |
| map() | Transform elements | list.stream().map(String::toUpperCase); | Intermediate |
| flatMap() | Flatten nested streams | list.stream().flatMap(s -> Arrays.stream(s.split(" "))); | Intermediate |
| distinct() | Remove duplicates | list.stream().distinct(); | Intermediate |
| sorted() | Sort elements | list.stream().sorted(); | Intermediate |
| limit() | Take first n elements | list.stream().limit(5); | Intermediate |
| skip() | Skip first n elements | list.stream().skip(2); | Intermediate |
| forEach() | Iterate elements | list.stream().forEach(System.out::println); | Terminal |
| collect() | Collect results | List<String> result = list.stream().collect(Collectors.toList()); | Terminal |
| reduce() | Aggregate elements | int sum = list.stream().reduce(0, Integer::sum); | Terminal |
| count() | Count elements | long total = list.stream().count(); | Terminal |
| anyMatch() | Check if any element matches | list.stream().anyMatch(s -> s.startsWith("A")); | Terminal |
| allMatch() | Check if all elements match | list.stream().allMatch(s -> s.length() > 0); | Terminal |
| noneMatch() | Check if no elements match | list.stream().noneMatch(s -> s.isEmpty()); | Terminal |
| findFirst() | Get first element | Optional<String> first = list.stream().findFirst(); | Terminal |
| findAny() | Get any element | Optional<String> any = list.stream().findAny(); | Terminal |
| Collectors.toList() | Collect stream to list | list.stream().collect(Collectors.toList()); | Utility |
| Collectors.toSet() | Collect stream to set | list.stream().collect(Collectors.toSet()); | Utility |
| Collectors.joining() | Join elements to string | list.stream().map(String::toUpperCase).collect(Collectors.joining(", ")); | Utility |
| Collectors.groupingBy() | Group elements by key | list.stream().collect(Collectors.groupingBy(String::length)); | Utility |
| Collectors.partitioningBy() | Partition elements by predicate | list.stream().collect(Collectors.partitioningBy(s -> s.length() > 3)); | Utility |