3 ms·
Iteration through a LinkedList isn't slower than through an ArrayList, in fact a simple test shows that on java 1.6.0_22 on my Macbook it is about 20% faster, a
by julian37 16y ago
Iteration through a LinkedList isn't slower than through an ArrayList, in fact a simple test shows that on java 1.6.0_22 on my Macbook it is about 20% faster, and on java 1.6.0_17 on Linux about 10% faster.
Have you actually compared performance before making that claim? I can't see any reason why it would be substantially slower on any platform, except maybe due to locality of reference issues because of the overhead of storing a pointer to the next element.
Compared to an ArrayList, a LinkedList is slow for random access as any treatise of the subject matter would tell you. See for example:
http://en.wikipedia.org/wiki/Linked_list#Linked_lists_vs._dynamic_arrays http://en.wikipedia.org/wiki/Linked_list#Linked_lists_vs._dy...