Professional Documents
Culture Documents
Arrays
Arrays
------
Array is a collection of similar type of elements which has continuous memory
locations.
Array is index-based, the first element of the array is stored at the 0th index, 1,
2nd element is stored on 1st index and so on.
2 Multidimensional Array
3 Jagged Array
Declaration of Array
--------------------
Instantiation of an Array
-------------------------
int a[];
a=new int[3];0 1 2
Initialisation of an Array
--------------------------
int a[];---->Declaration
a=new int[3];--->Instantiation
a[0]=11;---->Initialisation
a[1]=12;
a[2]=13;
It holds an array element in a variable, then executes the body of the loop.
Ex:
---
int a[]=new int[10];
for(int i:a){
body
}
Ex:
---
int[][] arr=new int[3][3];
column
0 1 2
Row--->0 1 2 3
1 4 5 6
2 7 8 9
Jagged Array:
-------------
Main intention of jagged array is to declar customized array.
EX:
---
int[] arr=new int[3][3];
arr[0]=new int[5];
arr[1]=new int[4];
arr[2]=new int[2];