Array Length in Java

前端 未结 16 1462
忘了有多久
忘了有多久 2020-11-30 21:27

I declared an array as shown below:

int[] arr = new int[10];

Then I assigned following values to the array:

arr[0] = 1;
arr         


        
16条回答
  •  隐瞒了意图╮
    2020-11-30 22:20

    Arrays are static memory allocation, so if you initialize an array of integers:

    int[] intArray = new int[15];
    

    The length will be always 15, no matter how many indexes are filled.

    And another thing, when you intialize an array of integers, all the indexes will be filled with "0".

提交回复
热议问题