5

Is there any difference between delaring an array like

int[] array = new int[10];

and declaring it like

int array[] = new int[10];

?

Both are valid in Java but I havent found any differences (initialization or something?) or is it just two different ways to describe the same thing for the compiler?

Josh Lee
  • 171,072
  • 38
  • 269
  • 275
Slim
  • 299
  • 3
  • 10

3 Answers3

11

They have no difference, but that notational difference allows this identity:

int[] array; int[][] matrix;

===

int array[], matrix[][];

===

int[] array, matrix[];

Here is the related specification page: http://java.sun.com/docs/books/jls/third_edition/html/arrays.html#17235

Ming-Tang
  • 17,410
  • 8
  • 38
  • 76
2

int array[] is the way C people do it, int[] array is the preferred syntax for Java. The functionality in either case is identical.

This is a good article about java coding style issues: Speaking the Java Language without an accent

Brad Mace
  • 27,194
  • 17
  • 102
  • 148
1

They both do the same thing.

prgmast3r
  • 413
  • 5
  • 8