Reputation: 901
On many posts on Stackoverflow people said that using bytes or shorts instead of integers did not reduce the memory usage or CPU utilization. However, if I have an array of bytes or shorts, would that array use less memory and/or be faster to iterate over than a similar array of integers.
To be specific: I'm asking about the primitive type.
Upvotes: 1
Views: 269
Reputation: 145
http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html
As mentioned in Java documentation byte/short can be used for saving memory in large arrays.
In case of byte, the variable declared as byte can also serve as a form of a documentation since its value is limited by the range. ex of byte (-128 to 127).
Also take a look at the excellent answers in the following post,
In java, is it more efficient to use byte or short instead of int and float instead of double?
Upvotes: 1