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?
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.