What are the advantages of TLongArrayList over long[]

141 views Asked by At

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[] ?

2

There are 2 answers

0
Joni On BEST ANSWER

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
T. Neidhart On

Versatility and usability of an ArrayList while using primitive longs to store the actual values.