Alex Rivera | Logout

Difference between int[] array and int array[]

Asked 2008-09-24T19:06:12.623
267

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?

Edit
Report

1 Answer

1

Yep, exactly the same. Personally, I prefer

int[] integers; 

because it makes it immediately obvious to anyone reading your code that integers is an array of int's, as opposed to

int integers[];

which doesn't make it all that obvious, particularly if you have multiple declarations in one line. But again, they are equivalent, so it comes down to personal preference.

Check out this page on arrays in Java for more in depth examples.

answered 2010-10-24T10:03:55.847

Your Answer