If I have an int
array structured like this:
private int[][] map = new int[400][400];
And I try to retrieve
map[100][200]
And that element isn't initialized, will i get a compiler/runtime error or will it return null? And is there any function to check if a given element/index exists/has been set?
As your array declaration is of a primitive type you won't get any compiler or runtime errors - the default value of 0 will be returned.
If your array had been an array of Objects, then the array would hold null
for any element not specifically assigned.
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