Home »
Java Programs »
Java Array Programs
Java program to find the length of an array
Given an integer array, we have to find the length of an array.
Submitted by Nidhi, on March 13, 2022
Problem Solution:
In this program, we will create an array of 10 integers then we will find the length of the array using the length property.
Program/Source Code:
The source code to find the length of an array is given below. The given program is compiled and executed successfully.
// Java program to find the length of
// an array
public class Main {
public static void main(String[] args) {
int[] intArr = new int[10];
int len = intArr.length;
System.out.println("Length of array is: " + len);
}
}
Output:
Length of array is: 10
Explanation:
In the above program, we created a public class Main. It contains a static method main().
The main() method is an entry point for the program. Here, we created an array intArr with 10 elements and get the length of the array using the length property. After that, we printed the result.
Java Array Programs »