September 2019
Intermediate to advanced
816 pages
18h 47m
English
Another common problem that we encounter in applications entails replacing the elements of a List that matches certain conditions.
In the following example, let's consider the Melon class:
public class Melon { private final String type; private final int weight; // constructor, getters, equals(), hashCode(), // toString() omitted for brevity}
And then, let's consider a List of Melon:
List<Melon> melons = new ArrayList<>();melons.add(new Melon("Apollo", 3000));melons.add(new Melon("Jade Dew", 3500));melons.add(new Melon("Cantaloupe", 1500));melons.add(new Melon("Gac", 1600));melons.add(new Melon("Hami", 1400));
Let's assume that we want to replace all melons weighing less than 3,000 grams with other melons ...