Difference between int[] array and int array[]

前端 未结 25 3005
轻奢々
轻奢々 2020-11-21 07:18

I have recently been thinking about the difference between the two ways of defining an array:

  1. int[] array
  2. int array[]
  3. <
相关标签:
25条回答
  • 2020-11-21 07:50

    They are semantically identical. The int array[] syntax was only added to help C programmers get used to java.

    int[] array is much preferable, and less confusing.

    0 讨论(0)
  • 2020-11-21 07:50

    There isn't any difference between the two; both declare an array of ints. However, the former is preferred since it keeps the type information all in one place. The latter is only really supported for the benefit of C/C++ programmers moving to Java.

    0 讨论(0)
  • 2020-11-21 07:50

    They are completely equivalent. int [] array is the preferred style. int array[] is just provided as an equivalent, C-compatible style.

    0 讨论(0)
  • 2020-11-21 07:51

    The most preferred option is int[] a - because int[] is the type, and a is the name. (your 2nd option is the same as this, with misplaced space)

    Functionally there is no difference between them.

    0 讨论(0)
  • 2020-11-21 07:51

    In Java, these are simply different syntactic methods of saying the same thing.

    0 讨论(0)
  • 2020-11-21 07:53

    There is no real difference; however,

    double[] items = new double[10];
    

    is preferred as it clearly indicates that the type is an array.

    0 讨论(0)
提交回复
热议问题