ArrayList vs LinkedList from memory allocation perspective

后端 未结 5 1792
时光取名叫无心
时光取名叫无心 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条回答
  •  遥遥无期
    2020-12-01 01:31

    Back of the envelope worst-case:

    500,000 names in an array sized to 1,000,000 = 500,000 used, 500,000 empty pointers in the unused portion of the allocated array.

    500,000 entries in a linked list = 3 pointers per entry (Node object holds current, prev, and next) = 1,5000,000 pointers in memory. (Then you have to add the size of the Node itself)

提交回复
热议问题