Java Program to Print Length of an Array

program in java to print length of array

In this tutorial, we will learn writing java program to create an array and print the length of the array. Our program will return the size of the given array.

For example

Case 1: if the given the array is {1, 2, 3, 4}.

           The output should be 4.

Case 2: if the given array  is {9, 8, 7, 6, 5}.                                    

The output should be 5.

Java Program to Print Length of an Array

Output

Java Program to Print Length of an Array

Explanation

For the given array {2, 4, 6, 8, 9, 4}, the arr.length() function will calculates the length of the array, the arr.length() function will return the length of array in ‘int’ data type.