A pair of programs are included in the source code which give a simple performance comparison between several different types of array-like collections. The first program, TimeFills, measures the time required to repeatedly fill an array-like collection with int values. Here's the relevant output from a sample run on a Windows 98 Athlon 1GHz system:

Java version 1.3.0
Java HotSpot(TM) Client VM
1.3.0-C
Sun Microsystems Inc.

Running initialization pass...
Running tests adding 50000 values to each collection
 with 1000 cycles for each collection type.
Ran int[] add test in 1.8 seconds
Ran DirectIntArray add test in 8.1 seconds
Ran IntArray add test in 8.6 seconds
Ran IntegerArray add test in 48.7 seconds
Ran ObjectArray of Integer add test in 48.8 seconds
Ran ArrayList of Integer add test in 48.2 seconds
Ran Vector of Integer add test in 49.7 seconds

For this test, which is only repeatedly creating the collection and filling it with values, it's obvious that the simple array (int[]) is dramatically superior to any of the alternatives.

DirectIntArray and IntArray are the next best alternatives. These are two versions of the type-specific collections library code for an array-like collection of type int; the only difference between the two is that IntArray is actually part of the library, using the shared base class methods which are core to the library, while DirectIntArray implements all the methods directly.

After these there's another dramatic jump in execution time to the remaining alternatives. These are all object collections, so they require the int values to be wrapped as Integer objects. The cost of this additional object creation and handling is evident in the times.

The second program, TimeSorts, measures the time required to do a simple bubble sort of the values in an array-like collection of . Here's the output from a pass of that test:

Java version 1.3.0
Java HotSpot(TM) Client VM
1.3.0-C
Sun Microsystems Inc.

Starting test run with 25000 values to be sorted.
Ran int[] sort test in 5.4 seconds
Ran DirectIntArray sort test in 12.1 seconds
Ran IntArray sort test in 12.0 seconds
Ran IntegerArray sort test in 36.9 seconds
Ran ObjectArray of Integer sort test in 37.2 seconds
Ran ArrayList of Integer sort test in 47.9 seconds
Ran Vector of Integer sort test in 44.2 seconds

Here again, the simple array is the best by a sizable margin. DirectIntArray and IntArray are still the next best alternatives, this time at least coming closer to the simple array performance.

There's still a big jump in execution time to the remaining alternatives, but for this test those alternatives are not as close as before. The object collections based on the type-specific collections library code, IntegerArray (with Integer values) and ObjectArray (with generic Object values). The standard collection classes from the Java libraries are considerably slower.

What these tests show is that if you really need the best performance, find a way to use a simple array for your data manipulation. Failing that, the type-specific collections library gives much better performance for primitive values and significantly better performance for object values than the standard Java collections.