In Java, it won't allow me to use a long for something like this:
long size = 0xFFFFFFFF; //2^32-1
byte [] data = new byte[size];
And an int can only go as high as 0x7FFFFFFF (2^31-1). Is it possible to declare a byte array of this size?
Answer is NO
as this is the max possible initialization:
int size = Integer.MAX_VALUE;
byte [] data = new byte[size];
Declare the size
as an int
and try again:
int size = 0x7FFFFFFF; // 0x7FFFFFFF == Integer.MAX_vALUE == 2^32-1
An array can only be declared to have a positive int
size, not a long
. And notice that the maximum int
positive value (and hence, the maximum possible size for an integer array, assuming there's enough memory available) is 0x7FFFFFFF == Integer.MAX_vALUE
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With