Java Array Length: Complete Guide

In Java, the keyword “length” can be used to represent the length of an array. The specific usage is: arrayName.length. For example, if there is an integer array intArray, you can obtain the length of the array through intArray.length. It is important to note that the length of an array is a property, not a method, so parentheses are not required.

Here is a sample code:

int[] intArray = {1, 2, 3, 4, 5};
int length = intArray.length;
System.out.println("数组的长度为:" + length);

The output will be: the length of the array is 5.

bannerAds