Length of an array in Java

Array.length is a property of an array object in Java ​which returns the number of elements in the array.

svg viewer

Code

The code snippet below illustrates the usage of the Array.length property in Java:

class HelloWorld {
public static void main( String args[] ) {
int[] arr = {2, 4, 6, 8, 10};
System.out.println("The length of the array is " + arr.length);
}
}

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved