Possible Duplicate:
java – Array brackets after variable name
When writing a Java function that accepts an array as a parameter, should the function definition have the brackets (“[]”) on the type or the variable name?
As in:
private int myFunction(int array[])
{
//do stuff here
}
or…
private int myFunction(int[] array)
{
//do stuff here
}
They both “work”, but is there a technical difference between the two?
There is no difference. But
int[] arrayis considered idiomatic Java.The logic is that
[]is part of the type (an array is a distinct type from a scalar), and sointand[]should live together. It’s also consistent with the notation for e.g. return types: