Java 12 introduces `Collectors::teeing`, a new static method that forwards stream elements to two separate collectors and merges their results using a provided function. This solves the common problem of needing to collect two distinct pieces of information from a single stream pass. The post demonstrates the feature with a min/max range example, explains the method signature with its four type parameters (T, R1, R2, R), and covers how stream characteristics (CONCURRENT, UNORDERED, IDENTITY_FINISH) are handled by the teeing collector.

7m read timeFrom nipafx.dev
Post cover image
Table of contents
▚ Motivation▚ Teeing Collector▚ Reflection

Sort: