Array - An array is the collection of similar kind of element stored in a single variable.
example int A[3] = {1,2,3}
Array index start with 0.
If you try to store/print value outside the index size, you'll get ArrayIndexOutOfBoundsException.
1. Single dimensional array
int a[] = {1 , 2, 3, 4, 5, 6};
1 2 3 4 5 6
2. 2 D Array
int a[][] = {
{1, 2, 3, 4, 5, 6}
{7, 8, 9, 1, 2, 3}
};
1 2 3 4 5 6
7 8 9 1 2 3
3. 3D Array
int b[][][] = new int[2][2][2]
4. Jagged Array
int a[][] = {
{1, 2, 3, 4}
{7, 8, 9}
{2, 4, 5, 6, 7, 8}
};
int k[][] = new int [3][];
k[0]= new int[4];
k[1]= new int[3];
k[2]= new int[5];
See the below example to use an array
example int A[3] = {1,2,3}
Array index start with 0.
If you try to store/print value outside the index size, you'll get ArrayIndexOutOfBoundsException.
1. Single dimensional array
int a[] = {1 , 2, 3, 4, 5, 6};
1 2 3 4 5 6
2. 2 D Array
int a[][] = {
{1, 2, 3, 4, 5, 6}
{7, 8, 9, 1, 2, 3}
};
1 2 3 4 5 6
7 8 9 1 2 3
3. 3D Array
int b[][][] = new int[2][2][2]
4. Jagged Array
int a[][] = {
{1, 2, 3, 4}
{7, 8, 9}
{2, 4, 5, 6, 7, 8}
};
int k[][] = new int [3][];
k[0]= new int[4];
k[1]= new int[3];
k[2]= new int[5];
See the below example to use an array
No comments:
Post a Comment