Skip to content

Instantly share code, notes, and snippets.

@hongbeomi
Created November 26, 2019 07:58
Show Gist options
  • Save hongbeomi/937ad1ad4f135cbb94b42a40ff29cde2 to your computer and use it in GitHub Desktop.
Save hongbeomi/937ad1ad4f135cbb94b42a40ff29cde2 to your computer and use it in GitHub Desktop.
public static List<Apple> filterApplesByColor(List<Apple> inventory, Color color) {
List<Apple> result = new ArrayList<>();
for (Apple apple: inventory) {
if ( apple.getColor().equals(color) ) {
result.add(apple);
}
}
return result;
}
// 구현한 메서드를 호출하기
List<Apple> greenApples = filterApplesByColor(inventory, GREEN);
List<Apple> redApples = filterApplesByColor(inventory, RED);
// 무게 정보 파라미터 추가하기
public static List<Apple> filterApplesByWeight(List<Apple> inventory, int weight) {
List<Apple> result = new ArrayList<>();
for (Apple apple : inventory) {
if (apple.getWeight() > weight) {
result.add(apple);
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment