The iterator returned by ArrayList has a "fail fast" mechanism. If no corresponding thread-safe object exists, synchronizedList in Collections can be used to make an ordinary ArrayList instance a thread-synchronized object. Only setting the value of the element does not modify the list structure. In this case, modifying the list structure refers to adding, deleting elements or changing the underlying array size. When multiple threads access an ArrayList instance and at least one thread changes the list structure, synchronization must be performed externally. Each time a new element is added to the ArrayList, the capacity is determined to grow, and the strategy for growth is considered, and there is a time cost.ĪrrayList is asynchronous. The capacity must be greater than or equal to the number of elements. The size, isEmpty, get, set, iterator, listIterator method calls are constant time, independent of the number of elements The time complexity of the add method call is O(n).Įach ArrayList instance has a capacity that is the size of the array used to hold elements. Mutable arrays implement the List interface as a collection of elements that can be null. Here are some of them, and we'll explain them in more detail in the source code analysis. Annotation summaryĪrrayList has about 100 lines of comments, which are fairly comprehensive. Let's start by looking at the List family:įrom the above, we often use about the above five sets:Īfter a brief overview of the features of various lists, in this article we'll take a look at how arrayLists work. Kotlin sets and 1 - The parent interface of the Collection class - Nuggets (juejin. This article begins by combing through the specific collections that are commonly used. In the previous article, we combed through the Kotlin collection interface.
0 Comments
Leave a Reply. |