In this tutorial, we will be learning a java program to count the total number present in the given array. This program is a basic program. To count the array elements we will be using an inbuilt length that will return the count of the array.
For example:
Suppose we have an array arr with the element
arr = [1,2,3,4,5,6]
Now to print the array length we can use arr.length which will return 6 as an output.
import java.util.*;
class Main{
public static void main(String ...a){
int arr[] = new int[]{ 1,2,3,4,5,6,7,8,9,10 };
System.out.println("Total elements in array are : " + arr.length);
}
}
Output