Why does java take so long to initialize two-dimensional arrays, starting with the first dimension, which is large?

I noticed that initializing a 2D array like this

case 1: -

int ar [] [] = new int [10000001][10] ;

it takes more time than its initialization

case 2: -

int ar[] [] = new int [10] [10000001] ;

in case 1, this time is about 4000 ms, but in case 2 it does not exceed 100 ms; why does this big difference exist?

+6
source share
1 answer

Strictly speaking, Java does not have 2D arrays: instead, it uses 1D arrays sorted into 1D arrays of arrays.

, , Java 10000001 10 , - 10 10000001 .

, .

+10

Source: https://habr.com/ru/post/1016602/


All Articles