Labs
In these labs we will use the functional interface Predicate and lambda-related methods.
com.example.lambdas.labs.PlanetFilteringLab
Call PlanetUtilities.filterPlanets, filtering for planets with "a" or "A" in the name.
(Solution: PlanetFilteringLab.java)
com.example.lambdas.labs.PlanetUtilities
Change filterPlanets to use the removeIf method.
* Do not operate on the input List. Instead, create a copy by passing the input List into a new ArrayList's constructor.
* filterPlanets used to add to a List, but removeIf removes from a List. How can you get the opposite of the input Predicate?
(Solution: PlanetUtilities3.java, PlanetFilteringLab2.java)
-
Create an overloaded
filterPlanetsthat takes twoPredicates, and filters forPlanets that match eitherPredicate. -
Call the new
filterPlanets, searching forPlanets with"a"or"y"in the name.
(Solution: PlanetUtilities4.java, PlanetFilteringLab3.java)