Java Reference
In-Depth Information
int
int
totalMembers
=
0
;
for
for
(
Artist artist
:
artists
) {
Stream
<
Artist
>
members
=
artist
.
getMembers
();
totalMembers
+=
members
.
count
();
}
3.
Evaluation
. Take a look at the signatures of these
Stream
methods. Are they eager or
lazy?
a.
boolean anyMatch(Predicate<? super T> predicate);
b.
Stream<T> limit(long maxSize);
4.
Higher-order functions
. Are these
Stream
functions higher order, and why?
a.
boolean anyMatch(Predicate<? super T> predicate);
b.
Stream<T> limit(long maxSize);
5.
Pure functions.
Are these lambda expressions side effect-free, or do they mutate state?
x
->
x
+
1
Here's the example code:
AtomicInteger count
=
new
new
AtomicInteger
(
0
);
List
<
String
>
origins
=
album
.
musicians
()
.
forEach
(
musician
->
count
.
incAndGet
();)
a. The lambda expression passed into
forEach
in the example.
6. Count the number of lowercase letters in a
String
(hint: look at the
chars
method on
String
).
7. Find the
String
with the largest number of lowercase letters from a
List<String>
.
You can return an
Optional<String>
to account for the empty list case.