Array Definition:
Array is an variable that holds multiple values of same data type.
How to get array length in java?
array length Definition:
arr.length give the length of the array where arr is the array name.
Syntax:
arrayname.length;
Array simple Program:
package array_pack;
class arr
{
private int arr[] = new int[2];
public void array_init()
{
arr[0] = 1;
arr[1] = 2;
}
public void array_print()
{
for(int i = 0; i<arr.length; i++)
System.out.println(arr[i]);
}
}
public class arr_process {
public static void main (String
args[])
{
arr a = new
arr();
a.array_init();
a.array_print();
}
}
Output:
1
2
Explanation:
First the program creates the instance for the class arr..Now with the help of the instance we are calling the array_init() function and array_print() function.
Note :
arr.length give the length of the array where arr is the array name.
Tags:
Array Declaration,Array,Array in java,A simple array program,array definition,array concept in java,programs,simple programs,java beginners,array length,
Thanks fr sharing... very helpful :) :)
ReplyDeleteSuper Cool :)
ReplyDelete