--
ArrayList implements the RandomAccess interface, and LinkedList does not. Note that Collections.binarySearch does take advantage of the RandomAccess property, to optimize searches. A LinkedList does not support efficient random access - An
ArrayListis much faster than aLinkedListfor random access, that is, when accessing arbitrary list elements using thegetmethod. Thegetmethod is implemented forLinkedLists, but it requires a sequential scan from the front or back of the list. This scan is very slow. - An
ArrayListis much faster thanLinkedListdoing a binary search on the large list of sorted element. - A
LinkedListare more efficient speed wise thanArrayListwhen inserting and removing at random places in the list multiple times. If you're just adding to the end of the list, anArrayListis what you want. - A
LinkedListis faster than anArrayListwhen elements are only added to the beginning of the list. - A
LinkedListhas a simple growth pattern of just adding and removing nodes when it needs to, but the ArrayList has a growth algorithm of (n*3)/2+1, meaning that each time the buffer is too small it will create a new one of size (n*3)/2+1 where n is the number of elements of the current buffer and there will be a significant amount of space wasted at the end. - The reversing a
LinkedListusingCollections.reverse. The internal algorithm does this, and gets reasonable performance, by using forward and backward iterators.
Comments
Post a Comment