Adding 1M elements to the head of List took 125 seconds on my computer. This means that you shouldn’t add too many elements to the head of big ArrayList. Methods specifying insertion position have to copy all array elements to the right from insertion point by System.arraycopy call, that’s why these methods have O(n) complexity (performance penalty is small if new element is added near the tail, but getting larger when insertion point moves towards the head). Single argument methods are adding new elements to the list tail. There are 2 pairs of methods used to add elements: If you need a resizable list of primitive type values, you should read a Trove library article. It is backed by an Object array, which size is dynamically adjusted while user adds or removes elements from the list. ArrayList methods will be divided into several groups and their performance will be discussed.ĪrrayList is a general list implementation suitable for most use cases. We will discuss most of possible ArrayList performance problems in this article.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |