3 ms·
You probably forgot that it's possible to remove current element via Iterator, which indeed gives us O(1) for LinkedList in best case. Removal from ArrayList is
by ivan_gammel 10y ago
You probably forgot that it's possible to remove current element via Iterator, which indeed gives us O(1) for LinkedList in best case. Removal from ArrayList is more expensive except the case when you remove the last element.
- leecarraher 10y agomy thoughts exactly. removing where you need random access to elements to me always = array list. Things i iterate through and manipulate = linked list, otherwise every get() is an O(n).
- imtringued 10y agoYou can always swap the current element with the last element and then delete the last element in an unordered list.
- deleted 10y ago[deleted]
- ivan_gammel 10y agojava.util.List is ordered by definition (first sentence in Javadoc, if you want to verify).