[list]
I'd better write down something before I forget
1. LinkedList is doubly linked, so it takes up more space and cannot hold as many elements as ArrayList.
2. Insertion, ArrayList is faster, in the same level, ArrayList may be two times faster, not that obvious with few elements (<100,000)
3. Deletion, LinkedList is generally faster, this is easy to understand as remove is O(1), there is one scenario that ArrayList can perform equally well, that is keeping remove from the tail of the list. The most time-consuming removal operation for ArrayList would be to keep removing the first element, i.e.
while (!list.isEmpty()) {
list.remove(0);
}
because internally, Java uses System.arraycopy to shift content starting from index+1 to index.
[/list]
I'd better write down something before I forget
1. LinkedList is doubly linked, so it takes up more space and cannot hold as many elements as ArrayList.
2. Insertion, ArrayList is faster, in the same level, ArrayList may be two times faster, not that obvious with few elements (<100,000)
3. Deletion, LinkedList is generally faster, this is easy to understand as remove is O(1), there is one scenario that ArrayList can perform equally well, that is keeping remove from the tail of the list. The most time-consuming removal operation for ArrayList would be to keep removing the first element, i.e.
while (!list.isEmpty()) {
list.remove(0);
}
because internally, Java uses System.arraycopy to shift content starting from index+1 to index.
[/list]