Home Help Java A Java Array Length
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Java Array Length

Advertisement
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:

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: June 13, 2013

Related Tutorials

Ask Questions?    Discuss: Java Array Length  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com