This other topic on Stack Overflow, "traditional for loop vs Iterator in Java", discusses the performance difference between using indexes and using iterators. The top answer points out that there's a very significant difference (a factor of 60.000) when dealing with containers such as LinkedList
.
I expect this has something to do with caching. If that's so, how do iterators get around this issue? If it has nothing to do with cache misses, what is it that makes iterators for non-contiguous containers so much faster?