Home >>Java Programs >Print the number of elements in an array java
In this example, we will create a java program to count and print the number of elements present in the array.
The number of elements present in a given array can be found by calculating the length of that array.
Algorithm:
public class Main
{
public static void main(String[] args)
{
int [] arr = new int [] {1, 2, 3, 4, 5, 6, 7, 8, 9};
System.out.println("Number of elements present in given array: " + arr.length);
}
}