Results for “Stream transformations”
Small, practical examples. Search by task or narrow things down below.
Calculate several numeric stream statistics
Java: Use summaryStatistics to calculate count, sum, minimum, maximum, and average in one pass.
Java✓ Tested
Check any and all stream elements
Java: Use short-circuiting match operations for predicates over a Java collection.
Java✓ Tested
Find the first matching stream value
Java: Use findFirst and an explicit default for an empty result.
Java✓ Tested
Join transformed stream values
Java: Use Collectors.joining after converting elements to strings.
Java✓ Tested
Take a page from a stream
Java: Use skip and limit with a known stable input order.
Java✓ Tested
Transform each stream value
Java: Use map to turn each input into a corresponding output.
Java✓ Tested
Flatten nested collections
Java: Use flatMap to concatenate nested Java lists into one stream.
Java✓ Tested
Group strings by their length
Java: Choose a TreeMap supplier when group keys must have deterministic order.
Java✓ Tested
Index records by a unique key
Java: Use toMap with an explicit merge rule so duplicate keys have defined behavior.
Java✓ Tested
Partition a collection by a predicate
Java: Use partitioningBy to retain both matching and nonmatching values.
Java✓ Tested
Append a stream to a log file
Linux Commands: Use tee -a to preserve existing log contents.
Linux Commands✓ Tested
Capture a command’s success-stream output
PowerShell: Assignment collects output values without requiring text redirection to a file.
PowerShell✓ Tested