Java program to find the length of an array

Given an integer array, we have to find the length of an array.
By Nidhi Last updated : December 23, 2023

Problem statement

In this program, we will create an array of 10 integers then we will find the length of the array using the length property.

Java program to find the length of an array

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 »


More Java Array Programs

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.