英文:
What are the advantages of TLongArrayList over long[]
问题
TLongArrayList在某些地方代替长整型原始数组使用,我想问一下使用TLongArrayList相比于long[]有什么好处?
英文:
I saw that in some places that the data structure TLongArrayList is used instead of an array of long primitives. I wish to ask what is the benefit to use TLongArrayList over long[] ?
答案1
得分: 2
TLongArrayList
类来自GNU Trove 项目,实现了一个动态数组数据结构(维基百科),用于存储原始的 long
值。
与原生的固定大小的 long[]
数组相比,“动态数组”的好处在于您可以添加和删除元素,包括在中间位置,而数据结构会自动扩展以满足使用需求。相比之下,当您创建一个数组时,必须在创建时决定大小,并且所有数组元素都在那时创建。对于固定大小的数组,您无法添加或删除元素,只能替换现有元素。
英文:
The TLongArrayList
class from the GNU Trove project implements a dynamic array data structure (wikipedia) for elements that are primitive long
values.
The benefit of "dynamic array" over the native fixed-sized long[]
array is that you can add and remove elements, including in the middle, and that the data structure automatically expands to meet usage. In comparison, when you create an array you have to decide the size at the time of creation, and all the array elements are created at that time. With a fixed sized array, you cannot add or remove elements, only replace existing elements.
答案2
得分: 1
ArrayList 使用原始 long 类型来存储实际值的多功能性和可用性。
英文:
Versatility and usability of an ArrayList while using primitive longs to store the actual values.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论