type [ ] array_name ; or type array_name[ ] ; |
array_name = new type[size] ; |
Note : 1) In Java array are dynamically allocated, i.e. memory to an array is allocated at run time. 2) We can traverse an array using a loop ( mainly for-each loop). 3) We can also declare and allocate memory to an array with a single statement by combining both declaration and allocation statement. For example : int[ ] arr = new int [5] ; |
type[ ] array_name = { List of elements separated by comma}; |
char[ ] alpha = {‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’};
Note : We can use loop to traverse multidimensional array. |