Yet another way to iterate over a collection. Coming in via jsr166 soon. Seeing CopyOnWriteArrayList beat ArrayList decisively suggests that optimizing it is defintely worth doing.
And of course the numbers below contain more low-hanging fruit if anyone still cares about the performance of LinkedList or Vector. Have you considered adding public ranged methods on Arrays? We currently only have the "deranged" Arrays.hashCode(Object[]) --- IteratorMicroBenchmark.java 9 May 2018 17:43:01 -0000 1.44 +++ IteratorMicroBenchmark.java 11 May 2018 18:18:37 -0000 @@ -34,6 +34,7 @@ import java.lang.ref.ReferenceQueue; import java.lang.ref.WeakReference; import java.util.ArrayDeque; +import java.util.Arrays; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -562,6 +563,12 @@ for (int i = 0; i < iterations; i++) { sum[0] = 0; x.replaceAll(sneakyAdder); - check.sum(sum[0]);}}}); + check.sum(sum[0]);}}}, + new Job(klazz + " hashCode") { + public void work() throws Throwable { + int hashCode = Arrays.hashCode(x.toArray()); + for (int i = 0; i < iterations; i++) { + if (x.hashCode() != hashCode) + throw new AssertionError();}}}); } } C2: Method Millis Ratio ArrayList hashCode 94 1.000 ArrayList$SubList hashCode 97 1.031 LinkedList hashCode 92 0.974 AbstractList$SubList hashCode 111 1.172 Vector hashCode 82 0.866 SynchronizedRandomAccessList hashCode 97 1.022 CopyOnWriteArrayList hashCode 8 0.091 COWSubList hashCode 8 0.090 C1: Method Millis Ratio ArrayList hashCode 112 1.000 ArrayList$SubList hashCode 118 1.060 LinkedList hashCode 118 1.054 AbstractList$SubList hashCode 276 2.472 Vector hashCode 126 1.132 SynchronizedRandomAccessList hashCode 293 2.620 CopyOnWriteArrayList hashCode 37 0.330 COWSubList hashCode 36 0.325