I am tasked with creating a toString()
method for each and every object in an ArrayList
. I have no idea how to go about doing this. This is the class with the ArrayList
public class DogManager {
private ArrayList<Dog> dogList;
public DogManager() {
this.dogList = new ArrayList<Dog>();
}
public void addDog(String nameOfDog) {
this.dogList.add(new Dog(nameOfDog));
}
public String toString() {
String results = "+";
for (int i = 0; i < this.dogList.size(); i++) {
results += " " + this.dogList.get(i);
}
return results;
}
}
I know the toString()
is wrong, but I can't figure out how to make it return a description for each of the objects in that list.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…