Interface List
Exist two most used implementation of this interface it is ArrayList and LinkedList. Let's go deeper about each
...
For further actions, you may consider blocking this person and/or reporting abuse
A nice summary!
One small comment: a
ConcurrentModificationException
does not only occur when two threads access the same collection. It may also happen that your own (single-threaded) code iterates over a collection, and makes changes to it during the iteration.For example:
This snippet will always throw a
ConcurrentModificationException
(except for empty collections) even though only a single thread is at work. We are mutating the collection while an iterator is still active. Maybe specialized collections, such as theCopyOnWriteArrayList
, can survive this loop without throwing an exception, but the generalCollection
contract specifies that this is an invalid case.Thank you, I am update the post
Time complexity of TreeSet guarantees O(log n) not O(n)
Oh, thank. You are true.
Since LinkedHashSet is designed/implemented on a HashTable Structure it is possible to be O(1) but it can easily be O(n) depending on a hash()
At the docs.oracle.com/javase/7/docs/api/... we see that is provide contant time for basic operation, and O(n) for iteration over a LinkedHashSet that means next require time proportional to the size of the set
Then I think you meant constant time O(1) for add, contains, and remove. Iteration on any structure is always O(n).
Yeah! for this operation I meant
Thanks for the interesting article. Usually, I tend to use LinkedList when I mostly appending a lot of items of which the size I don’t know and/or when I iterate over all elements. When I’m doing a lot of random accesses, I use ArrayList. In your table, both list implementations have O(1), is that still true when the whole array needs to be copied due expansion? And what about actual time? Do you know any benchmarks for different use cases? I really would be interested.