This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "count all objece in arraylist" Watch "count all objece in arraylist" New topic
Author

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: 13869
    
  10

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
Object within an Object - URGENT NEED
Brain Twister
Using indexOf(Object o) for String[]
programming to the interface
How can I manually add values to ArrayList[]