Stream examples
Get the unique surnames in uppercase of the first 15 book
authors that are 50 years old or over.
[Link]()
.map(book -> [Link]())
.filter(author -> [Link]() >= 50)
.distinct()
.limit(15)
.map(Author::getSurname)
.map(String::toUpperCase)
.collect(toList());
Compute the sum of ages of all female authors younger than 25.
[Link]()
Intermediate operations .map(Book::getAuthor)
. Always return streams. . Lazily executed. .filter(a -> [Link]() == [Link])
.map(Author::getAge)
.filter(age -> age < 25)
.reduce(0, Integer::sum):
Common examples include:
Preserves Preserves Preserves
Function
count type order Terminal operations
. Return concrete types or produce a side effect.
map . Eagerly executed.
Common examples include:
filter
Function Output When to use
distinct
reduce concrete type to cumulate elements
sorted collect list, map or set to group elements
to perform a side effect
peek forEach side effect
on elements
BROUGHT TO YOU BY