An array is an indexed collection of fixed number of homogeneous data element. The main advantege of array is we can represent multiple values under the same name. So that readability of the code improved.
But the main Limitation of array is once we created an array There is no chape of increasing/decreasing size basedon own requirement. Here memory point of view arrays concept is not recomanded to use.
We can resolve this problem by using collections:
- Array declaration
- Array creation
- Array initialization
- declaration creation, Initialization in a signle line
- lenght vs Lenght()
- Annonymous Array
- Array element assignments
- Array variable assignment
1. Array declaration
A. Singel dimenshion Array declaration
- int [] a;
- int a[];
- int []a;
int[] intArray = new int[10]; // combining both statements in one
First one recomended because type is clearly seperate from the name. At the time of declaration we cant't specify the size.
int [5] a; // can't specify the size
B. 2D Array declaration:-
- Int [] [] a;
- int [][]a;
- int a[][];
- int [] a[];
- int [] []a;
- int []a[];
C. 3D Array Declaration
- int [] [][] a;
- int a[][][];
- int [][][]a;
- int [][]a;
- int[] [][]a;
- int[] a[][];
- int[] []a[];
- int[][] []a;
- int[][] a[];
- int [][]a[];
- int []a[][];
if we want to Specify the dimention before the variable it it possible only for the first variable
int []a []b //[]a allow but []b not allow
Tags:
Java
