从列表中删除对象

如果我需要从List中删除一个对象,你可以删除哪一个,假设字符串“abc”
linkedList或ArrayList? (我想,两者都是一样的)
如果我使用Linkedlist和arraylist,那么时间和空间的复杂性是多少
(我相信两者都会有相同的时间复杂度O(n)

两者都具有相同的时间复杂度 – O(n),但是恕我直言, LinkedList版本会更快,特别是在大型列表中,因为当你从数组中删除一个元素( ArrayList )时,右边的所有元素都必须向左移动 -为了填充清空的数组元素,而LinkedList只需要重新连接4个引用

以下是其他列表方法的时间复杂性:

 For LinkedList 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 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)