The Collectors class has many more methods that return Collector objects that can be used in the collect() method. The following are the most interesting:
- toList(): This method returns Collector that groups all the elements of Stream into List.
- toCollection(): This method returns Collector that groups all the elements of Stream into Collection. This method returns as parameter an expression that creates Collection, which will be used internally by Collector and returned at the end of its execution.
- averagingInt(), averagingLong(), and averagingDouble(): These methods return Collector that calculates the average of int, long, and double values, respectively. They receive as parameters an expression to convert an element of ...