My question is that there is a method printPetInfoByName() searches the list of pets for every pet of a given name, and prints the pet’s information, using the toString() method. The arraylist is of type Pet and name is given from main method (i haven't coded it yet) I need to print info of a pet using toString() by searching arraylist. If the given name is present in list then it will print info.
my code looks like this
but it produces error > incompatible types: Pet cannot be converted to CharSequence for line 20 if i write for(String search:list) then it gives error that Pet cannot be converted to String for line 18
containsdoesn't know what to do with aPet. You probably need to change it to something like it's name, making the lineif(name.contains(search.getName())).getNamemethod in thePetclass to return the name of thePet.