Skip to content

Sorting Overhaul for Java 7

February 14, 2013

Java 7 made some drastic changes to how sorting working, and I thought I’d share that with you. First, Collections.sort(List) actually creates an array by calling list.toArray() this is done to avoid the n^2 log n performance hit of trying to sort a linked list. And then delegates all sorting to Arrays.sort() .

Arrays#sort() – is overloaded for with many different signatures.

sort(primitive arrays) – int, long, short, char, byte, float, double – All use DualPivotQuicksort 

sort(array of Object) – sort using TimSort which is based on Merge Sort.

Both of these algorithms have a minimum threshold where instead of running the algorithm, they run some sort of Insertion sort. If the number of elements is less than 32, then binarySort and insertion sort is called for performance reasons.


From → Java

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: