Labs

In these labs we will use the functional interface Predicate and lambda-related methods.

  1. com.example.lambdas.labs.PlanetFilteringLab

Call PlanetUtilities.filterPlanets, filtering for planets with "a" or "A" in the name.

(Solution: PlanetFilteringLab.java)

  1. 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)

  1. Create an overloaded filterPlanets that takes two Predicates, and filters for Planets that match either Predicate.

  2. Call the new filterPlanets, searching for Planets with "a" or "y" in the name.

(Solution: PlanetUtilities4.java, PlanetFilteringLab3.java)


Prev -- Up