From this article,
hand-written counted loop is about 3x faster
than an enhanced for loop for iterating over arraylists.
Firstly, what do they mean by “hand-written counted loop”? They didn’t explicitly elaborate what this means. Secondly, why is it that this holds true only for arraylists and not the other collections?
I assume they mean
ArrayList supports efficient random access and removing the Iterator can make a small improvement. (or a large relative improvement if you have a loop which doesn’t do anything else)
For other collections e.g. LinkedList, it faster to use an Iterator because
get(n)is slower. For Set there is noget(n)