RSS2.0

Looking Something??



[Java] Array - Java Programming Language

Thursday, March 6, 2008

Array – Java Programming Language

Array Declaration and Initialization :

a) 1 Dimensional Array :

Declaration : |data type|[ ] |variable name|;

|data type||variable name|[ ];

Example : int x[ ]; /* or */ int [ ] x;

Initialize Array / Instansiate Object with constructor :

|variable name|= new |data type|[sum_of_array];

Example : x = new int[10];

We can also write these together :

|data type||variable name|[ ] = new |data type|[sum_of_array];

Example : int x[ ] = new int [10];

b) 2 Dimensional Array :

Declaration : |data type|[ ][ ] |variable name|;

|data type||variable name|[ ][ ];

Example : int x[ ][ ]; /* or */ int [ ][ ] x;

Initialize Array / Instansiate Object with constructor :

|variable name|= new |data type|[sum_of_array][sum_of_array];

Example : x = new int[10][10];

We can also write these together :

|data type||variable name|[ ] = new |data type|[sum_of_array] [sum_of_array];

Example : int x[ ][ ] = new int [10][10];

0 comments: