how do i print the element "e" in arraylist "list" out?
ArrayList<Dog> list = new ArrayList<Dog>();
Dog e = new Dog();
list.add(e);
System.out.println(list);
how do i print the element "e" in arraylist "list" out?
ArrayList<Dog> list = new ArrayList<Dog>();
Dog e = new Dog();
list.add(e);
System.out.println(list);
Your code requires that the Dog class has overridden the toString() method so that it knows how to print itself out. Otherwise, your code looks correct.
First make sure that Dog class implements the method public String toString() then use
System.out.println(list.get(index))
where index is the position inside the list. Of course since you provide your implementation you can decide how dog prints itself.
You should override toString() method in your Dog class. which will be called when you use this object in sysout.