This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
that we can do with the help of get also, like for(int i=0;i<=al.length;i++) // write get here get(i);
Joined: Feb 09, 2007
Thanks a lot Remko Strating. I hope , iterator() is also going to help us when we take ArrayList into a Collection, as we dont have get method in Collection. But what is the need of taking an arrayList into a collection..?
You would use a Collection to allow you room to change which implementation you wanted to use. Suppost originally all you needed was something to hold a list of objects, well an ArrayList will do fine. But then you realise that the values of the objects in this collection must be unique so you change it to a Set. If you had used the get() method of List to iterate through your collection you would need to change this code. If you had used an Iterator then nothing needs changed.