How can the length of a Java array be obtained?

In Java, you can use the keyword “length” to get the length of an array.

For example

int[] array = {1, 2, 3, 4, 5};
int length = array.length;
System.out.println(length); // 输出 5

Please note that length is a member variable, not a method. Therefore, there is no need to add parentheses after it.

bannerAds