CHAPTER 7
LAMBDAS AND STREAMS
214
elements in a category. The simplest use of this parameter is to pass
toSet()
,
which results in a map whose values are sets of elements rather than lists.
Alternatively, you can pass
toCollection(collectionFactory)
, which lets
you create the collections into which each category of elements is placed. This
gives you the flexibility to choose any collection type you want. Another simple
use of the two-argument form of
groupingBy
is to pass
counting()
as the down-
stream collector. This results in a map that associates each category with the
num-
ber
of elements in the category, rather than a collection containing the elements.
That’s what you saw in the frequency table example at the beginning of this item:
Map
freq = words
.collect(
Do'stlaringiz bilan baham: