print arraylist element?

前端 未结 7 394
日久生厌
日久生厌 2021-01-11 13:59

how do i print the element \"e\" in arraylist \"list\" out?

 ArrayList list = new ArrayList();
 Dog e = new Dog();
 list.add(e);
 Syste         


        
7条回答
  •  走了就别回头了
    2021-01-11 14:11

    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.

提交回复
热议问题