Checking for Criteria
Transformation of data doesn’t always have to result in a particular value like an average or a list. Sometimes a "transformation" may actually be an act of verifying if all the elements in a collection satisfy some characteristics, and the result may be a mere boolean value. This may be perceived as a combination of the filter operation on a collection followed by reduce. The Stream API simplifies and provides nice methods for transformations like this, with good efficiency. Let’s take a look.
Let’s say we’re asked to find in a given collection if any person has at least one email address and separately if anyone has at least ten email addresses. We can use the anyMatch function to check if any element in a collection ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access