The definition of an array created using


1. Definition of an array of
arrays refer to the same type of a set of variables , each data array is called an element.
The array itself as reference data types.
2. What can be stored in an array of
arrays can be stored in any type of element, but an array can only store the same type of elements.
3. The length of the array: the array need to specify the length of the array in the creation of a determined length can not be modified
superscript array
for each element of the array is automatically assigned the subscript
of the array index starts from 0
index of the maximum length of the array is the - a
way to create an array of 4:
(1) data type [] = new variable name data type [length of the array];
EG: int [] a = new int [10];
(2) data type [] variable name = {value, value, value} ...
EG: int [] = {1,2,3,4} B;
assignment mode 5. array
assignment was created: int [] arg = new int [] {1,2 , 3,4}
created when assignment: int [] arg = {1,2,3,4,5,6,2,3,4 };
the subscript assignment: the most common
int [] arg = new int [ 10]; // no empty array unit 10 assignment
arg [0] = 189; // data representative of the array 189 into the arg position 0 No.
 6. array each have a default initialization value
byte / Short / int / 0 Long
a float 0.0f
Double 0.0d
reference data types null
char '\ u0000'
Boolean to false
7. The array index value by,
through the array: for looping through index
int [] a = {1, } 2,4,3,5;
for (int I = 0; I <a.length; I ++) {
    System.out.println (a [I]);
}
 8. the multidimensional array
on each element of the array of data is an array, so you get a multidimensional array.
(Statement 1. multidimensional array: Data Type [] [] args = new data type [length of the array] [];
(2, assignment
                                               int [] [] args = new int [. 5] [];
            args [0] new new int = [. 3];
            args [. 1] = new new int [2];
            args [. 3] = new new int [2];
            args [0] [0] =. 1;
            args [0] [. 1] =. 1;
            args [. 4] [. 1] =. 1;
            args [. 4] [2] = 2;
(3 copies of the array
length of the array can not be adjusted once it is determined, we can change the length of the array by copying the contents of the array .System. method arraycopy
arraycopy (the src Object, int srcPos, Object dest, destPos int, int length);
original array, the array of the original start position, the target array, the start position of the target array, copying length
eg: int [] arr1 = { 6,54, } 34,2,5,2;
 int [] = arr2 is new new int [. 5];
 System.arraycopy (of arr1,. 3, arr2 is, 0,. 3);
 System.out.println (of Arrays.toString (arr2 is));
( 4Arrays use
Arrays.sort () ; // Sort Arrays.toString (); // array specified string representation
of a value of the array subscripts (5 randomly   Math.random ();
Example: int [] arr = {1,2,3,4};
    // generating 0- (arr.length-1) is an integer value, the array index is
    int index = (int) (Math.random () * arr.length);
    int rand = arr [index];
    System.out.println (rand);
added:
Random itself only between decimal (~ 0. 1),
Random () * means that the generated arr.length decimal between 0 ~ arr.length, (int) ( Math .random () * arr.length) means rounding is mandatory, so it becomes an integer between generation-arr.length. 1 ~ 0

(variable parameter. 6
syntax: String args ...
    Note: variable parameter It can only be the last parameter list.





Guess you like

Origin www.cnblogs.com/yxj808/p/11945074.html