Java Collections – List Performance Measurements
I decided to put the following List-based data structures to the test in order to determine which is fastest. I tested Vector, ArrayList, LinkedList and Stack.
Evaluating performance
I am testing how many iterations of the basic operations (add(), get(), remove()) can by performed within 1000 ms. In other words, I am testing number of operations/per second between the various collections.
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); } }
Performance Leaders
- LinkedList
- ArrayList
- Vector
- Stack
List Performance Benchmark

Full Program Listing
package com.avaldes.tutorials;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;
import java.util.Vector;
public class ListPerformanceBenchmark {
final static int SMALL = 1000;
final static int MEDIUM = 10000;
final static int LARGE = 100000;
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 testStackIterations(Stack 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.push(obj);
list.search(5);
list.pop();
}
System.out.println(list.getClass()+ " (" + length+ "), iterations: "
+ iterations);
}
public static void main(String[] args) {
testIterations(new Vector(), SMALL);
testIterations(new Vector(), MEDIUM);
testIterations(new Vector(), LARGE);
testStackIterations(new Stack(), SMALL);
testStackIterations(new Stack(), MEDIUM);
testStackIterations(new Stack(), LARGE);
testIterations(new ArrayList(), SMALL);
testIterations(new ArrayList(), MEDIUM);
testIterations(new ArrayList(), LARGE);
testIterations(new LinkedList(), SMALL);
testIterations(new LinkedList(), MEDIUM);
testIterations(new LinkedList(), LARGE);
}
}
Output

class java.util.Vector (1000), iterations: 1483581 class java.util.Vector (10000), iterations: 149238 class java.util.Vector (100000), iterations: 15220 class java.util.Stack (1000), iterations: 1315147 class java.util.Stack (10000), iterations: 131550 class java.util.Stack (100000), iterations: 15348 class java.util.ArrayList (1000), iterations: 1197541 class java.util.ArrayList (10000), iterations: 162981 class java.util.ArrayList (100000), iterations: 15288 class java.util.LinkedList (1000), iterations: 17132537 class java.util.LinkedList (10000), iterations: 17610603 class java.util.LinkedList (100000), iterations: 16858130
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