Search code examples
javaarraysprimitiveautoboxing

is there comfortable array without autoboxing


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.


Solution

  • 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.