Skip to content

Instantly share code, notes, and snippets.

@HDBandit
Last active December 15, 2015 19:16
Show Gist options
  • Save HDBandit/49522d058c674f931f2d to your computer and use it in GitHub Desktop.
Save HDBandit/49522d058c674f931f2d to your computer and use it in GitHub Desktop.
// business logic
public static List<Car> filterCarsByBrandAndColor(List<Car> cars, String brand, String color) {
// we can reuse the method to filtering by brand
List<Car> filteredCarsByBrand = filterCarsByBrand(cars, brand);
ArrayList<Car> filteredCars = new ArrayList<Car>();
for (Car car : cars) {
if (color.equals(car.getColor())) {
filteredCars.add(car);
}
}
return filteredCars;
}
...
// from your programm, you can call it from this way
List<Car> filteredCars = filterCarsByBrand(cars, "Ferrari", "red");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment