Showing posts with label iterator. Show all posts
Showing posts with label iterator. Show all posts

Friday, June 8, 2012

Why would iterating over a List be faster than indexing through it?


Reading the Java documentation for the ADT List it says:




The List interface provides four methods for positional (indexed) access to list elements. Lists (like Java arrays) are zero based. Note that these operations may execute in time proportional to the index value for some implementations (the LinkedList class, for example). Thus, iterating over the elements in a list is typically preferable to indexing through it if the caller does not know the implementation.


Monday, May 7, 2012

traditional for loop vs Iterator in Java


Is there any performance testing results available in comparing traditional for loop vs Iterator while traversing a ArrayList,HashMap and other collections?

Monday, February 20, 2012

Is there any Relation between Iterator.hasNext and for-each loop


I was using JProfiler for profiling of my application, as it is a huge application so I am very aware of its performance and efficiency.