两者都具有相同的时间复杂度-O(n),但是恕我直言,该
linkedList版本会更快,尤其是在大型列表中,因为当您从数组(
ArrayList)中删除一个元素时,右侧的所有元素都必须向左移动-
顺序来填充空数组元素,而
linkedList只需重新连接4个引用
这是其他列表方法的时间复杂度:
For linkedList<E> get(int index) - O(n) add(E element) - O(1) add(int index, E element) - O(n) remove(int index) - O(n) Iterator.remove() is O(1) ListIterator.add(E element) - O(1)For ArrayList<E> get(int index) is O(1) add(E element) is O(1) amortized, but O(n) worst-case since the array must be resized and copied add(int index, E element) is O(n - index) amortized, O(n) worst-case remove(int index) - O(n - index) (removing last is O(1)) Iterator.remove() - O(n - index) ListIterator.add(E element) - O(n - index)



