is there comfortable array without autoboxing

116 views Asked by At

I can't find a comfortable array, which does not use autoboxing. I need to take a very careful look at the memory-size and want to use primitive structures like int instead of their object-equivalent like Integer.

Using int[], is very un-comfortable in matters of fixed size / positions. But I cannot afford using something like LinkedList and ListArray because they can only be used with Integer instead of int.

So i would like to ask, if there is any comfortable array, which can use primitive data-structures, like int, instead of Objects.

2

There are 2 answers

0
Stefano Sanfilippo On BEST ANSWER

You can't do it directly with Java collections, but there are a few external libraries implementing collections of primitive types.

For instance, GNU Trove has a TIntArrayList and Apache Commons Primitives has a ArrayIntList. Both will suit your needs.

0
Marcin Świerczyński On

The short answer is: no, Java does not provide ArrayList of ints by default. ArrayList can only contain Object subclasses and primitives don't inherit Object.

However, you could write your own implementation of List that operates on ints or - preferably - use something like TIntArrayList.