Java: How ArrayList manages memory

后端 未结 5 850
花落未央
花落未央 2021-01-12 17:13

In my Data Structures class we have studies the Java ArrayList class, and how it grows the underlying array when a user adds more elements. That is understood. However, I ca

5条回答
  •  鱼传尺愫
    2021-01-12 18:12

    There is not much gain by resizing the ArrayList internal array, even you are using ArrayList to hold a large object.

    List list = new ArrayList();
    

    list will only hold reference to LargeObject instance, and not holding LargeObject instance itself.

    Reference doesn't consume much space. (Think it as pointer in C)

提交回复
热议问题