An array is a variable representing a collection of same-typed data. Arrays are usefull in representing vectors, matrix, string analysis, sorting a tables.
One-Dimensional Array:
In java, an array is created in two steps. First, an array variable is to be declared and the second is to create a array object using new operator by specifying the number of memory location required. These two operations are done using two different statements.
int arr[];
arr=new int[10];
The first statement int arr[]; declare a Integer type variable arr. The second statement allocates memory for 10 int type. Now arr can handle 10 int type values. Each value can be accessed by using index value 0 to 9. Supposing 10 elements are 12,32,43,13,25,34,76,45,23,34 then.
arr[0] ---> 12
arr[1] ---> 32
arr[6] ---> 76
and so on……
No comments:
Post a Comment