Declaring arrays in Java

前端 未结 4 1939
予麋鹿
予麋鹿 2020-12-21 16:01

After reading, I came to know that, arrays in Java are objects. The name of the array is not the actual array, but just a reference. The new operator creates th

4条回答
  •  北海茫月
    2020-12-21 16:15

    int[] myArray = new int[5];
    

    In this we are specifying the length five to an array

    int[] myArray= new int[]{5,7,3};
    

    In this we are passing three elements and then specifying the length three.

    int[] myArray= {5,7,3};
    

    In this we are passing the element which will automatically specified the length three.

提交回复
热议问题