File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 15081

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
It's not a secret anymore!