Answer: – An array is used in java programming to store large amount of data in one variable with different index or subscript. The availability to use single name to represent a collection of item and to refer to an item by specifying the item number enables us to develop concise and efficient program. For example, a loop with the subscript as the control variable can be used to read entire array, perform calculation and, print the result. When array is declared in any programming language including java, they specify size of array variable and only limit number of items can be stored in that array variable. All other programming language provide facility of only fixed size array with one dimension or multi dimension.

Java provide facility including one dimensional and two-dimensional array and is called variable size array. The variable size array very length of size in columns but it fixes row size. According to size of value, length of memory location increases or decrease. The variable size array used in java programming to store data in multi-dimensional array with their different length.  Before using of variable size array its row can be fix but its column can be empty and after that multiple values with different length can be stored in that array. Java treats multi-dimensional array as “array of array” or variable size array. It is possible to declare a two-dimensional array as array of array or variable size array. An example of variable size array can be declaring in the following format –

int x[][]=new int[3][];
x[0]=new int[2];
x[1]=new int[4];
x[2]=new int[3];

Here, variable X is declared as two-dimensional array with fixed number of rows but its column size differs from each other. Variable X[0] contains two column, X[1] contains four column and X[2] contains three column. After every declaration, column size varies from different variables and show that these variables are called variable size.

Advertisements