Difference between int[] array and int array[]

2018-12-31 01:53发布

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

  1. int[] array
  2. int array[]

Is there a difference?

标签: java arrays
25条回答
旧人旧事旧时光
2楼-- · 2018-12-31 02:44

They are the same, but there is an important difference between these statements:

// 1.
int regular, array[];
// 2.
int[] regular, array;

in 1. regular is just an int, as opposed to 2. where both regular and array are arrays of int's.

The second statement you have is therefore preferred, since it is more clear. The first form is also discouraged according to this tutorial on Oracle.

查看更多
登录 后发表回答