C'est ce que j'ai fait jusqu'à présent, il compte simplement tout ce que la liste de tableaux contient comme ayant le mot recherché. Cela me donne le nombre de tableaux originaux mais n'imprime aucun résultat correspondant.
import java.util.ArrayList;
public class Test {
public static void main(String[] args) {
ArrayList<Animal> animalList = new ArrayList<>();
animalList.add(new Dog("Dog", 43.3, "Husky", 1));
animalList.add(new Dog("Dog", 80.5, "Labrador", 2));
animalList.add(new Dog("Dog", 33.1, "Shiba Inu", 1));
animalList.add(new Dog("Dog", 120.8, "Malamute", 2));
animalList.add(new Dog("Dog", 43.3, "Chiwawa", 0));
animalList.add(new Cat("Cat", 14.3, "Short Hair"));
animalList.add(new Cat("Cat", 11.2, "Siamese"));
animalList.add(new Cat("Cat", 15.1, "Bengal"));
animalList.add(new Cat("Cat", 9.6, "Persian"));
animalList.add(new Bird("Bird", 2.5, "White Plumage", false));
animalList.add(new Bird("Bird", 1.2, "Long Beak", true));
animalList.add(new Bird("Bird", 0.3, "Colorful", true));
animalList.add(new Bird("Bird", 3.6, "Swims", true));
searchForAnimalClass(animalList, "Bird");
}
private static ArrayList<Animal> searchForAnimalClass(ArrayList<Animal> list, String animalClass){
ArrayList<Animal> result= new ArrayList<>();
int count = 0;
for(Animal x:list) {
if(x.getAnimalClass().contains(animalClass));
count++;
if(x instanceof Animal)
result.add(x);
}
System.out.println("Number of animals with Animal Class of '" + animalClass + "', is equal to = " + count);
return result;
}
}