This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv 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 REST with Spring (video course) this week in the Spring 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: 580
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: 15041

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 8 API documentation
I agree. Here's the link:
subject: count all objece in arraylist
jQuery in Action, 3rd edition