I have a Car class, each Car class has a list of Wheel class and each Wheel class has a integer field airPressure.
public class Car {
private List<Wheel> wheels;
public List<Wheel> getWheels() {
return wheels;
}
}
public class Wheel {
private int airPressure;
public int getAirPressure() {
return airPressure;
}
}
Now I have a list of Cars and I have to filter out all cars that have any wheels' air pressure larger than defaultValue. I'm filtering cars but I need to iterate through all wheels. Now I have code like this:
I have: List<Cars> cars, int defaultValue
List<Cars> filteredCars = cars.stream()
.filter(car -> car.getWheels().get(0).getAirPressure() < defaultValue)
.filter(car -> car.getWheels().get(1).getAirPressure() < defaultValue)
.filter(car -> car.getWheels().get(2).getAirPressure() < defaultValue)
...
How to iterate wheels of each car when filtering cars?