DZone

Java Stream’s Collectors methods fit most use-cases. They allow returning either a Collection or a scalar. For the former, you use one of the toXXX() method, for the latter, one of the reducing() one.

Let’s imagine an e-commerce platform that implements a shopping cart. The cart is modeled as the following:

Source: DZone