Java Streams API Cheatsheet

Quick reference for Java Streams: creation, intermediate operations, terminal operations, and collector utilities.

ItemDescriptionExampleCategory
stream()Create sequential stream from collectionList<String> list = ...; Stream<String> s = list.stream();Creation
parallelStream()Create parallel streamStream<String> s = list.parallelStream();Creation
Stream.of()Create stream from valuesStream<Integer> s = Stream.of(1,2,3);Creation
Arrays.stream()Create stream from arrayStream<String> s = Arrays.stream(arr);Creation
IntStream.range()Create int stream for rangeIntStream.range(1,5).forEach(System.out::println);Creation
filter()Filter elements by predicatelist.stream().filter(s -> s.startsWith("A"));Intermediate
map()Transform elementslist.stream().map(String::toUpperCase);Intermediate
flatMap()Flatten nested streamslist.stream().flatMap(s -> Arrays.stream(s.split(" ")));Intermediate
distinct()Remove duplicateslist.stream().distinct();Intermediate
sorted()Sort elementslist.stream().sorted();Intermediate
limit()Take first n elementslist.stream().limit(5);Intermediate
skip()Skip first n elementslist.stream().skip(2);Intermediate
forEach()Iterate elementslist.stream().forEach(System.out::println);Terminal
collect()Collect resultsList<String> result = list.stream().collect(Collectors.toList());Terminal
reduce()Aggregate elementsint sum = list.stream().reduce(0, Integer::sum);Terminal
count()Count elementslong total = list.stream().count();Terminal
anyMatch()Check if any element matcheslist.stream().anyMatch(s -> s.startsWith("A"));Terminal
allMatch()Check if all elements matchlist.stream().allMatch(s -> s.length() > 0);Terminal
noneMatch()Check if no elements matchlist.stream().noneMatch(s -> s.isEmpty());Terminal
findFirst()Get first elementOptional<String> first = list.stream().findFirst();Terminal
findAny()Get any elementOptional<String> any = list.stream().findAny();Terminal
Collectors.toList()Collect stream to listlist.stream().collect(Collectors.toList());Utility
Collectors.toSet()Collect stream to setlist.stream().collect(Collectors.toSet());Utility
Collectors.joining()Join elements to stringlist.stream().map(String::toUpperCase).collect(Collectors.joining(", "));Utility
Collectors.groupingBy()Group elements by keylist.stream().collect(Collectors.groupingBy(String::length));Utility
Collectors.partitioningBy()Partition elements by predicatelist.stream().collect(Collectors.partitioningBy(s -> s.length() > 3));Utility