Array Length in Java

前端 未结 16 1494
忘了有多久
忘了有多久 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:03

    To find length of an array A you should use the length property. It is as A.length, do not use A.length() its mainly used for size of string related objects.

    The length property will always show the total allocated space to the array during initialization.

    If you ever have any of these kind of problems the simple way is to run it. Happy Programming!

提交回复
热议问题