The definition of java-based array

1. The array definition format is divided into dynamic and static

    (1) static initialization format: two kinds

      Data Type [] = new Array Name Data Type [] {element 1, element 2, element 3 ...}

      Example //
      int [] arr = new int [  ] {10,20,30,40};

      Data Type [] = {array name element 1, element 2, element 3 ...};

      Example //
      int [] arr = {10,20,30,40} ;

    Dynamic Definition Format (2) of the array

      • Data Type [] = new Array name Data type [array length];

      •  Data type variable name [] = new data type [array size]; Learn to

      • // dynamic array initialization

      • Example //
        // int 3 is defined as the length of the array
        int [] arr = new int [ 3];

        // define the length of the double array 5
        double [] arr = new double [ 5];

        // define the length of an array of char 5
        char [] arr = new char [ 5];

        // define the length of the array of strings 4
        String [] arr = new String [ 4];

    (3) the characteristics of the index value of the array?

        Array index is starting from 0, +1 each time.

 

Guess you like

Origin www.cnblogs.com/suitang/p/11517415.html