How to find size of array in java with example

If you want to know size or length of array than use inbuilt in java function

Syntax:-

array_name.length

array_name is name of array

length is used to fined size/index value of the array. If you change number of element in array, length function not get effect.

The output of array_name.length is size of array

Note:-
# The output of array_name.length is always integer
# Array_name is variable

Example:-

class group{
public static void main(String argn[]){
int data [] = {45,87,124,78,127,2};

System.out.println("Index value of data array is "+data.length);

for(int i = 0; i < data.length; i++)
System.out.println(data[i]);
}
}

Output:-

Index value of data array is 6
45
87
124
78
127
2




Previous Code:-
Initialization of arrays

List Code:-
Java codes

Next Code:-
Enhanced for loop

Java Programs:-
List of Java Programs

5 Comments

  1. really nice explanation for beginners thank you

    ReplyDelete
  2. Thank you for the blog. Found it interesting and useful. Java is a general purpose, high-level, class-based and object-oriented programming language. And we provide Java training in Chennai at Fita.

    ReplyDelete
  3. Thank you for the blog. Found it interesting and useful. Java is a general purpose, high-level, class-based and object-oriented programming language. And we provide Java training in Chennai at Fita.

    ReplyDelete

Add your comments here

Back to Top