Effective Java



Download 2,19 Mb.
Pdf ko'rish
bet187/341
Sana11.07.2022
Hajmi2,19 Mb.
#776765
1   ...   183   184   185   186   187   188   189   190   ...   341
Bog'liq
Effective Java



CHAPTER 7
LAMBDAS AND STREAMS
206
Even if you have little previous exposure to streams, this program is not hard
to understand. It opens the dictionary file in a 
try
-with-resources block, obtaining
a stream consisting of all the lines in the file. The 
stream
variable is named 
words
to suggest that each element in the stream is a word. The pipeline on this stream
has no intermediate operations; its terminal operation collects all the words into a
map that groups the words by their alphabetized form (Item 46). This is exactly
the same map that was constructed in both previous versions of the program. Then
a new 
Stream>
is opened on the 
values()
view of the map. The
elements in this stream are, of course, the anagram groups. The stream is filtered
so that all of the groups whose size is less than 
minGroupSize
are ignored, and
finally, the remaining groups are printed by the terminal operation 
forEach

Note that the lambda parameter names were chosen carefully. The parameter
g
should really be named 
group
, but the resulting line of code would be too wide
for the book. 

Download 2,19 Mb.

Do'stlaringiz bilan baham:
1   ...   183   184   185   186   187   188   189   190   ...   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