Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (6.1k points)
Can anybody tell me how to calculate the array length?

1 Answer

0 votes
by (11.7k points)

Array length is nothing but the number of elements present in an array. There is no already defined method in java that can give the length of an array. But the array length can be found by using array attribute length. 

Every array has an already defined length property whose value is the size of the array. Size is nothing but the total number of elements present in an array. Length property can be invoked by using the dot (.) operator further followed by the array name.

 

Code: 

public class ArrayLengthCode   

{   

public static void main(String[] args)   

{   

//initializing an string type array named country   

String[] country = { "India", "France", "Spain", "USA", "UAE", "Germany", "Brazil"};  

//length is an Array attribute that determines the array length   

int arrayLength=country.length;   

//prints length of an array  

System.out.println("The size of the array is: " + arrayLength);   

}   

Want to become an expert in Java, check out this Java Tutorial from Intellipaat. 

Related questions

0 votes
1 answer
asked Feb 7, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
asked Feb 25, 2021 in Java by RohitSingh (2.6k points)
0 votes
1 answer
asked Jul 25, 2019 in Salesforce by Kartik12234 (11.9k points)
0 votes
1 answer
asked Feb 20, 2021 in Java by sheela_singh (9.5k points)

Browse Categories

...