TLongArrayList相对于long[]的优势是什么?

huangapple go评论65阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年8月9日 22:35:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/63327587.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定