标签:
For LinkedList<E>
get(int index)
is O(n)add(E element)
is O(1)add(int index, E element)
is O(n)remove(int index)
is O(n)Iterator.remove()
is O(1) <--- main benefit of LinkedList<E>
ListIterator.add(E element)
is O(1) <--- main benefit of LinkedList<E>
For ArrayList<E>
get(int index)
is O(1) <--- main benefit of ArrayList<E>
add(E element)
is O(1) amortized, but O(n) worst-case since the array must be resized and copiedadd(int index, E element)
is O(n - index) amortized, but O(n) worst-case (as above)remove(int index)
is O(n - index) (i.e. removing last is O(1))Iterator.remove()
is O(n - index)ListIterator.add(E element)
is O(n - index)标签:
原文地址:http://www.cnblogs.com/wuyun-blog/p/4694634.html