O'Reilly logo

Java 9 Concurrency Cookbook - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

There's more...

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required