Possible Duplicate:
When to use LinkedList<> over ArrayList<>?
This is a genuine attempt to know when would one use a LinkedList;
From what i understand since the java.util.LinkedList doesn't support random access, the only way to get the nth element is to skip from 1 to (n-1) or use get(n) which itself is very inefficient. So why would one use a LinkedList? An ArrayList would serve for most part unless you want to iterate the collection from both sides using a ListIterator?
Think about this method:
List list = // choose your list here
list.add(0, new Object());
For large lists, LinkedList
will heavily out-perform ArrayList
. The same applies for
list.remove(0);
... and many other methods. For more information, I suggest reading about the java.util.Deque
interface, which is also implemented by LinkedList
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With