I want to use List<E>, but the only way I'm ever going to use is
E remove(int index)
I am interested in the return value of this method (deleted E). I never need a method remove(E e).
The only constructor I will ever need is to take it Collection<? extends E>.
If it Listis ArrayList, the method remove(int index)has a time complexity of O (n), because you have to shuffle the elements after the deleted element in one place on the left.
If it Listis LinkedList, the method remove(int index)also has O (n) time complexity, because although it takes O (1) time to change the links in an element, you have to find the element in index index, intersecting List.
If I’m only interested in a method remove(int index), is it possible to write an implementation List<E>that he optimized for this method, so that the method remove(int index)has time complexity better than O (n)?
source
share