wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes count all objece in arraylist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "count all objece in arraylist" Watch "count all objece in arraylist" New topic

count all objece in arraylist

jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
I have a class A which has a array list, each object inside the array list contain a array list , likewise it go .Here,i want to count all object inside the arraylist of class A(which means arraylist's object and its object's array list object).

For that ,I have to iterate all the arraylist,or any efficient way to do this?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074

Class ArrayList has a size() method which tells you have many elements the list has. But this will not automatically look inside ArrayLists that are in your ArrayList. So yes, you will have to iterate.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
I agree. Here's the link: http://aspose.com/file-tools
subject: count all objece in arraylist
Similar Threads
How can I manually add values to ArrayList[]
programming to the interface
Brain Twister
Using indexOf(Object o) for String[]
Object within an Object - URGENT NEED