Big Data and Hadoop Training @$80 or Rs. 6,000 only - valid till Oct 17th Apply Now!

Java Array Length

Ads
 

Java Array Length

Java array is a collection of similar data type which store elements in a contiguous memory location.

Java array is a collection of similar data type which store elements in a contiguous memory location.

Java Array Length

In this section you will find a program to find the length of array in java. An array is collection of similar data type. To find the length of array is a simple program in java. Using length function you can find the length of array.

Syntax :  array-name. length

Example : int a[]  = { 10,20,30,40,50};

If you have to find the length of an array a, you can use a.length, it will return the length of array i.e. 5.

Code to find the length of an array

public class Length {
	public static void main(String args[])
	{
		int a[]= {12,23,0,90,76,40};
		System.out.print("Length of array = ");
		System.out.print(a.length);		
	}
}

In the above code declaration and initialization of  an array a, and finding the length of an array by a.length, returning the length of array a.

Output: When you compile and execute the code output will as below:

Ads

Ads