why LinkedList doesn't have initialCapacity in java?

前端 未结 6 1022
不知归路
不知归路 2021-02-07 00:54

I wonder why LinkedList doesn\'t have initialCapacity.

I know good when to use ArrayList and when LinkedList.

6条回答
  •  再見小時候
    2021-02-07 01:47

    LinkedList by nature does not have "capacity", since it does not allocate memory to the items before the items are added to the list. Each item in a LinkedList holds a pointer to the next in the list.

    http://www.stoimen.com/blog/wp-content/uploads/2012/06/0.-Arrays-vs.-linked-list.png

    There would be no point in allocating memory to the list beforehand, since LinkedList does not have capacity.

提交回复
热议问题