for (int i = 0; i <a.length; i ++ )
System.out.print l n (a [i]);
Once the array is created, it cannot be resized. If during the
execution of the program need to frequently change the size of the
array, it is better to use a different data structure called a list of
arrays (array list).
When you create and the array can be initialisation Rowan initial
values :
int [] small Array = { 1, 2, 3, 4 , 5 , 6 , 7 } ;
Note that in this case you do not need to use the new operation .
Copying arrays
If the arrays are the same, then one can be copied to another as
follows :
int [] small Array = {1, 2, 3, 4, 5, 6 , 7} ;
int [] b = sma l l Array ;
b [5] = 1 2 ; // Now element sma l l Array [5] is also 12
If you need to copy the elements of one array to another, use the
arraycopy method from the System . Its call looks like this:
System . and rr ausoru ( from , from I ndex , to , to I ndex ,
count );
The to array must be large enough to accommodate all of the copied
elements.
For example, shown below are two operators create an array and
then copy the last five element s of the first array to the second.
Copying starts at i = 2 ( that is , at the third position ) in the source
array, and the elements to be copied are placed into the target array
starting at i = 3 (that is , at the fourth element ) .
int [] sma l l Array = {1, 2, 3, 4, 5, 6 , 7} ;
int [] bigArray = {101, 102, 103, 104, 105, 106, 107 , 108, 109
};
System. a rra y c opu (sma l l Array , 2, bigArray , 3, 5 );
for (int i = 0; i < bigArray .length; i ++)
System.print (i + " , " + bigArray [i ]);