A stream describes how values move through a sequence of operations. Intermediate operations such as filter and map build a pipeline; a terminal operation such as sum, reduce or toArray asks the pipeline to produce a result. Keep each operation tied to one part of the requirement.
Order changes behavior. Limiting a batch before sorting can discard the smallest value. Removing duplicates is appropriate for a directory, but loses separate adjustments in a balance calculation. An empty pipeline still needs a defined result: sum yields zero, while a reduction returns its supplied identity. Work through a short input by hand, including a repeated value and the exact boundary, before deciding the order of the operations.