Java Collections – ArrayList vs LinkedList Performance
For this test, I decided to evaluate LinkedList vs ArrayList and see which one is fastest once and for all for the basic operations of add(), get() and remove(). From the tests I performed, it appears that LinkedList is quite a bit faster than ArrayList especially as the size of the collection grows.
Benchmark Leaders
- #1. LinkedList
- #2. ArrayList
Benchmark ArrayList vs. LinkedList (# iterations/Sec)

Full Program Listing
package com.avaldes.tutorials;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class LinkedListVsArrayBenchmark {
public static void testIterations(List list, int length) {
Object obj = new Object();
for (int i=0; i<length; i++) list.add(obj);
long startTime = System.currentTimeMillis();
int iterations = 0;
while (System.currentTimeMillis()-startTime < 1000) {
iterations++;
list.add(obj);
list.get(5);
list.remove(3);
}
System.out.println(list.getClass()+ " (" + length
+ "), iterations: " + iterations);
}
public static void main(String[] args) {
testIterations(new ArrayList(), 1000);
testIterations(new ArrayList(), 10000);
testIterations(new ArrayList(), 100000);
testIterations(new ArrayList(), 1000000);
testIterations(new ArrayList(), 10000000);
testIterations(new LinkedList(), 1000);
testIterations(new LinkedList(), 10000);
testIterations(new LinkedList(), 100000);
testIterations(new LinkedList(), 1000000);
testIterations(new LinkedList(), 10000000);
}
}
Output

class java.util.ArrayList (1000), iterations: 1196419 class java.util.ArrayList (10000), iterations: 163545 class java.util.ArrayList (100000), iterations: 15098 class java.util.ArrayList (1000000), iterations: 625 class java.util.ArrayList (10000000), iterations: 64 class java.util.LinkedList (1000), iterations: 9061265 class java.util.LinkedList (10000), iterations: 18942521 class java.util.LinkedList (100000), iterations: 24066964 class java.util.LinkedList (1000000), iterations: 18879194 class java.util.LinkedList (10000000), iterations: 19924783
Other Related Posts
Map Examples
- Hashtable Example
Simple example shows you step by step how to use Hashtable - HashMap Example
Simple example shows you step by step how to use HashMap - TreeMap Example
Simple example shows you step by step how to use TreeMap to sort a collection - EnumMap Example
Simple example shows you step by step how to use EnumMap for type-safety and speed of finite list of elements - WeakHashMap Example
Simple example shows you step by step how to use WeakHashMap - LinkedHashMap Example
Simple example shows you step by step how to use LinkedHashMap - Performance Comparison HashMap vs Hashtable vs TreeMap
Performance Comparison - Performance Comparison HashMap vs Hashtable vs TreeMap Benchmark Test
List Examples
- Stack Example
Simple example shows you step by step how to use Stack - Vector Example
Simple example shows you step by step how to use Vector - LinkedList Example
Simple example shows you step by step how to use LinkedList - ArrayList Example
Simple example shows you step by step how to use ArrayList - Performance Comparison between the four list implementations
Performance Comparison of ArrayList, LinkedList, Vector, and Stack - Performance Comparison ArrayList vs LinkedList
Performance Comparison - ArrayList vs LinkedList
Set Examples
- BitSet Example
Simple example shows you step by step how to use BitSet - EnumSet Example
Simple example shows you step by step how to use EnumSet - HashSet Example
Simple example shows you step by step how to use HashSet - TreeSet Example
Simple example shows you step by step how to use TreeSet - LinkedHashSet Example
Simple example shows you step by step how to use LinkedHashSet
Leave a Reply