public interface AdressBook {
public Collection<String> getAdresses();
}
Collection<AdressBook> books;
Collection<String> addresses;
// Collection is initialized
// Collects all the addresses from all the address books
addresses = books.stream().flatMap((b) -> b.getAdresses().stream()).collect(Collectors.toList());
Reduce
Combines all the values.
Collection<Integer> integers;
Integer sumation;
// Collection is initialized
// All the values are added together
sumation = integers.stream().reduce(this::sum);
Some streams include the most common reduction functions:
integers.stream().sum();
Consume (Apply to All)
Apply a function to all the elements.
Collection<Integer> integers;
// Collection is initialized
// Increases all the values
integers.stream().forEach(this::increase);