Last week, I for a custom Stream . I received a intriguing comment on Twitter: described a use-case Collector Hats off to you, Miguel! Your comment revealed a method I didn’t know! So I decided to investigate what is the method about. teeing() Returns a Collector that is a composite of two downstream collectors. Every element passed to the resulting collector is processed by both downstream collectors, then their results are merged using the specified merge function into the final result. The resulting collector functions do the following: * supplier: creates a result container that contains result containers obtained by calling each collector’s supplier * accumulator: calls each collector’s accumulator with its result container and the input element * combiner: calls each collector’s combiner with two result containers * finisher: calls each collector’s finisher with its result container, then calls the supplied merger and returns its result. — JavaDocs We can indeed replace our custom with two simple implementations, one aggregating price rows and the other summing the cart’s price. Collector Collector Let’s look at the final code and explain it line by line. { cart.getProducts() .entrySet() .stream() .map(CartRow:: ) .collect(Collectors.teeing( Collectors.reducing( BigDecimal.ZERO, CartRow::getRowPrice, BigDecimal::add), Collectors.toList(), PriceAndRows:: )); } PriceAndRows public getPriceAndRows (Cart cart) return new // 1 // 2 // 3 // 4 // 5 // 6 // 7 new // 8 Map each to a Entry CartRow Call the method teeing() The first collector computes the price. It's a simple call, with: reducing() The starting element A function to extract a from a Price CartRow A to add two prices together BinaryOperator The second collector aggregates the into a list CartRow Finally, the last parameter creates a new object that aggregates the results from the first and the second collector On the implementation side, : teeing() Extracts each of the individual components of both , , , , and Collector i.e. supplier() accumulator() combiner() finisher() Pairs them side-by-side Creates a single new by passing the pairs Collector Thus, there will be a single Collector a single pass in the end. and I hope this post made you consider using creating a custom . Thanks again to Miguel! teeing() before Collector By the way, I’m always happy to learn new things. In case you’ve got insights to share, you can use the commenting system below or Twitter. The complete source code for this post can be found on in Maven format. Github To go further: A real-world example of a Stream Collector Custom collectors in Java 8 Teeing Javadoc Originally published at A Java Geek on May 9th, 2021