I read in Bruce Eckel's Thinking in
Java that an ArrayList
allows rapid access to elements, but is slow when inserting and removing elements from the middle of the list. Also that a LinkedList has
inexpensive insertions and deletions from the middle of the list but is
relatively slow for random access.
I thought I would
test this out so I wrote the following code:
When I run, I get the following:
As I would have expected accessing the random values is much faster for the ArrayList than the LinkedList. But why is it marginally quicker to add to the middle of the ArrayList?
Shouldn't the LinkedList be much better with this one?
Thoughts appreciated.