The Artima Developer Community
Sponsored Link

Java Buzz Forum
When to use LinkedList? Never?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
dion

Posts: 5028
Nickname: dion
Registered: Feb, 2003

Dion Almaer is the Editor-in-Chief for TheServerSide.com, and is an enterprise Java evangelist
When to use LinkedList? Never? Posted: Jul 12, 2005 5:09 PM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by dion.
Original Post: When to use LinkedList? Never?
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
Latest Java Buzz Posts
Latest Java Buzz Posts by dion
Latest Posts From techno.blog(Dion)

Advertisement

I liked reading the Java Specialists' Newsletter from Heinz.

An interesting statement is this: "ArrayList is faster than LinkedList, except when you remove an element from the middle of the list." I have heard this on more than one occasion, and a few months ago, decided to try out how true that statement really was.

How many Java developers actually test the affect that a particular collection type would have on the performance? I would be willing ~0.01%.

Heinz goes on to benchmark both lists working at the beginning, middle, and end of sample lists:

beginning ArrayList took 4346 beginning LinkedList took 0 middle ArrayList took 2104 middle LinkedList took 26728 end ArrayList took 731 end LinkedList took 1242

And the conclusion is hilarious:

So, when should you use LinkedList? For a long list that works as a FIFO queue, the LinkedList should be faster than the ArrayList. However, even faster is the ArrayBlockingQueue or the CircularArrayList that I wrote a few years ago. The answer is probably "never".

A cool tool would be one that goes through and tests various Lists in your live code. AOP could wrap around the creation and inject different versions ;)

Of course, this would only be used AFTER we found that the Collection was a bottleneck. Who would optimize prematurely? :)

Read: When to use LinkedList? Never?

Topic: T-shirt-first development Previous Topic   Next Topic Topic: [DrunkAndRetired.com Podcast] Episode 12 - 4th of July, Sausage, Simplifying Symbols

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use