Concept of array in java

                                 Concept of array in java

 Hello,Everyone I am back with my blog about Concept of array in java with respect to Exception handling in java,

Java array is an object the contains elements of similar data type.

The most convenient loop for accessing the elements of only arrays & collections this loop has introduced in 1.5 versions.

Every array in java is “Object”.

For-each loop is the most convenient loop to access the elements of arrays & collections but the limitation of this loop is applicable for arrays & collections and it is not general loop.

       Scenarios of array declaration allowed

Array Declaration
declaration allowed in java
Int[ ]   x; 
YES
Int   []x;

YES
Int    x[ ];

YES
Int  [ ]   x;
NO
Int[ ]  a,b;
YES



For java programmer strongly recommended to use,

 Int[ ]   x;   because variable name is  clearly separated from type.


There are two types of array.
1. Single Dimensional Array
          2.  Multidimensional Array

Following are some scenarios where which shows dimension of array declaration respectively,

S.No
Array Declaration
Dimension
1
Int[ ]  a,b;
A= 1 ,B=1  .
2
Int[ ] a[ ],b;
A=2  ,B=1   .
3
Int[ ] a[ ],b[ ];
A= 2 ,B= 2 .
4
Int[ ]  [ ]a,b;
A=2  ,B=2   .
5
Int[ ]  [  ]a,b[ ];
A= 2 ,B= 3  .
6
Int[ ]  [  ]a,[ ]b;
Compiler Error

 If we are specifying variable after dimensions compile will give Compiler Error.

At time of array creation compulsory you should specify size otherwise we will get  compile time error.
e.g int[ ]  a=new int [ ];    // compile time error.

If we are specifying array size with negative int value then compile will give runtime Exception sayine ” NegativeArraySizeException”.
e.g int[ ]  a=new int [-5 ];    //  error at runtime.

Maximum size of array in java allowed for int data types is,

e.g int[ ]  a=new int [ 2147483647]; 


       Finally thank you for sparing your valuable time on reading my blog and stay connected for my next blog. Connect me Socially:linkedin  twitter  facebook


Comments