Effective Java



Download 2,19 Mb.
Pdf ko'rish
bet193/341
Sana11.07.2022
Hajmi2,19 Mb.
#776765
1   ...   189   190   191   192   193   194   195   196   ...   341
Bog'liq
Effective Java



CHAPTER 7
LAMBDAS AND STREAMS
212
comparator, so we’re sorting the words from most frequent to least frequent. Then
it’s a simple matter to limit the stream to ten words and collect them into a list.
The previous code snippets use 
Scanner
’s 
stream
method to get a stream over
the scanner. This method was added in Java 9. If you’re using an earlier release,
you can translate the scanner, which implements 
Iterator
, into a stream using an
adapter similar to the one in Item 47 (
streamOf(Iterable)
).
So what about the other thirty-six methods in 
Collectors
? Most of them
exist to let you collect streams into maps, which is far more complicated than col-
lecting them into true collections. Each stream element is associated with a key
and a value
, and multiple stream elements can be associated with the same key.
The simplest map collector is 
toMap(keyMapper,
valueMapper)
, which takes
two functions, one of which maps a stream element to a key, the other, to a value.
We used this collector in our 
fromString
implementation in Item 34 to make a
map from the string form of an enum to the enum itself:

Download 2,19 Mb.

Do'stlaringiz bilan baham:
1   ...   189   190   191   192   193   194   195   196   ...   341




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish