The definition of an array of java

Package Penalty for java03;
 / * 
initialize the array: is to create an array, to which the old saying some default value of 

two common ways to initialize: 
    1, dynamic initialization (specified length) 
    2, static initialization (specify the content) 

 dynamic array initialization format: 
    data type [] = new array data type name [array size]; 
      split into two steps: data type [] array name; 
                    array = new name data type [array size]; 

    Analysis: 
        left data type is an array among the saved data, all unified type 
        [] brackets on behalf of an array 
        of data left of the name is the name of an array of 
        new representatives to create an array of motion 
        data types must be consistent with the data type of the left side of 
        the array is the length of the array how much can be saved data, int a digital 

  still initialize an array format: 
  array type [] = new array array type name [] {element 1, element 2, .....}; 
  split into two steps: data type [] array name ; 
                    array = new name data type [] {element 1, element 2, .....}; 
  
        omitted format:
            Data Type [] = {Title array element 1, element 2, .....}; is not supported in two steps 
        matters Note: 
        Although not directly tell initializing a static array length, but inside the braces in accordance with the specific content elements, also can also be directly extrapolated automatic 

suggestions: explicit content with static arrays, dynamic arrays do not know the contents 
* 
* * / 
public  class Domo01Array {
     public  static  void main (String [] args) {
 //         create an array, which can save 60 data int 
        int [] = array1 new new  int [60 ]; 

//         create an array 60 can store data of type double 
        double [] = array2 new new  double [80 ]; 

//         create an array, a string can store 5 
        String [] at array3 = new newString [. 5 ]; 

//         create an array, int is used to hold the whole number, in particular 12,23,45,56 
        int [] = array4 new new  int [] {12,23,45,56 }; 

//         create an array used to hold the string: "Hello", "World", "Java" 
        string [] = array5 new new string [] { "Hello", "World", "Java" }; 
    } 
}

 

Guess you like

Origin www.cnblogs.com/spp666/p/11692509.html