public static void main(String[] args) { int [][]shatner = new int[1][1]; int []rat = new int[4]; shatner[0] = rat; System.out.println(shatner[0][3]); }
surprised, exit 0, why Java does not check for such an indexOutOfBound error?
Do not be surprised. shatner [0] is an array (rat) and has a length of 4. So shartner [0] [3] is a rat [3], which turns out to be 0 ..
Where do you see the "indexOutOfBound error"? The code performs the following actions:
int
.
0- shatner int[4].
shatner
int[4]
. shatner - . 4. , shatner [0] [3] .
, Java IndexOutOfBoundsException. , .
shatner[0] = rat;
, 0- shatner 4, shatner[0][4] .
shatner[0][4]
, java , . shatner [1] [1], - {{0},{0}} .
{{0},{0}}
However, then you assign an integer to the first element, turning it {{0,0,0,0},{0}}into memory, so Java resolves the newly assigned index.
{{0,0,0,0},{0}}
Arrays should not be rectangular in Java. It is a jagged array and works great.
Source: https://habr.com/ru/post/1742827/More articles:list of multiple arguments with NS_REQUIRES_NIL_TERMINATION - listA list with nonzero entries ends with null. Sync problem? - listDisplaying the contents (rather than saving) of a downloaded file using Django - djangoTabHost NullPointerException in layout - androidFacebook iPhone SDK: Show Progress Bar When Uploading Image - iphoneHow can I send GET data to multiple URLs simultaneously using cURL? - phpC # unit test code questions - c #Visual Studio highlights source code in bold - visual-studio-2005Loading NIB using [NSBundle loadNibNamed: owner:], but the window does not appear in the foreground - objective-cIs there a way to run plug-in applications for eclipse without fully launching the eclipse platform - eclipseAll Articles