Most memory efficient way to grow an array in Java?

前端 未结 12 1275
陌清茗
陌清茗 2020-12-13 19:18

I\'m not too concerned about time efficiency (the operation will be rare), but rather about memory efficiency: Can I grow the array without temporarily having all th

12条回答
  •  醉酒成梦
    2020-12-13 20:04

    How about a linked list coupled with an array that holds only references.

    The linked list can grow without having to allocate new memory, the array would ensure you have easy access. And every time the array becomes to small, you can simply trash the entire array and build it up again from the linked list.

    alt text

提交回复
热议问题