Search code examples
javagenericsspace-efficiency

Java Byte/byte array space efficiency comparison


I need to create a space efficient 2D array for a large number of 8 bit values. I began writing my class using a few layers of abstraction and generics to allow for code reuse. Once I got to implementing the concrete class it occurred to me I cannot pass in a primitive type as a generic class argument and I would have to use a wrapper class. Because I am concerned about space efficiency, I need to know: what is the space efficiency difference between a Byte array using the wrapper class compared to a primitive byte array?


Solution

  • Yes, primitives are light-weight compared to corresponding Wrapper class objects.

    You can read about it here : Primitives vs Wrappers