Array
====================================================
- Array is a collection of similar type of elements which has contiguous memory
location.
-Array is an object which contains elelmet of same data type.
-element of array is sored into contigeous memory location.
- Array is a index based where i can store my first number on 0th index, second
nuymber on 1st index,
third number on 2nd index and so on.
syntax and example->
int b[] = {8,7,12,6,9,5,33,1} ;
int arr[]= new int[8]; // array declaration
arr[0]= 8;
arr[1]=7;
arr[2]= 12;
arr[3]= 6;
arr[4]=9;
arr[5] = 5;
arr[6]= 33;
arr[7]=1;
note : when you try to insert extra element in the array when your array is
completly full
or you array index is not present then it will throw array index out of bound
exception.
Example->
int arr[]= new int[8]; // array declaration
arr[0]= 8;
arr[1]=7;
arr[2]= 12;
arr[3]= 6;
arr[4]=9;
arr[5] = 5;
arr[6]= 33;
arr[7]=1;
[Link]([Link]);
for(int x : arr ) { //for each loop
[Link](x);
}
[Link]("==============================");
String strArr[] = new String[3];
strArr[0]= "Shital";
strArr[1]="Mayur";
for(String y : strArr) { //for each loop
[Link](y);
}
//when u take inpust from users
Scanner sc = new Scanner([Link]);
int p[]= new int[4];
for(int i=0; i< [Link];i++) {
[Link]("Enter the number in "+i+" position");
p[i]= [Link]();
}
[Link]("Numbers in array which are entered by user");
for(int z :p) {
[Link](z);
}