ArrayList vs LinkedList from memory allocation perspective

后端 未结 5 1789
时光取名叫无心
时光取名叫无心 2020-12-01 00:58

I need to store a large amount of information, say for example \'names\' in a java List. The number of items can change (or in short I cannot predefine the size). I am of th

5条回答
  •  -上瘾入骨i
    2020-12-01 01:18

    ArrayList.trimToSize() may satisfy you.

    Trims the capacity of this ArrayList instance to be the list's current size. An application can use this operation to minimize the storage of an ArrayList instance.

    By the way, in ArrayList Java6, it's not double capacity, it's about 1.5 times max size is reached.

提交回复
热议问题