191. Filtering, flattening, and mapping collectors

Let's assume that we have the following Melon class and List of Melon:

public class Melon {

private final String type;
private final int weight;
private final List<String> pests;

// constructors, getters, setters, equals(),
// hashCode(), toString() omitted for brevity
}

List<Melon> melons = Arrays.asList(new Melon("Crenshaw", 2000),
new Melon("Hemi", 1600), new Melon("Gac", 3000),
new Melon("Hemi", 2000), new Melon("Crenshaw", 1700),
new Melon("Gac", 3000), new Melon("Hemi", 2600));

The Java Stream API provides filtering(), flatMapping(), and mapping(), especially for use in multi-level reductions (such as the downstream of groupingBy() or partitioningBy()).

Conceptually, the goal of filtering() is the same as filter(), the goal of flatMapping() is the same as flatMap(), and the goal of mapping() is the as map().

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.119.106