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 the stream into int, long, or double. The three methods return a double value.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.47.39