Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between type[] varName and type varName[]?

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?

like image 873
Slim Avatar asked Dec 16 '10 01:12

Slim


People also ask

What is the difference between int [] A and int a []?

Difference between “int[] a” and “int a[]” for 1-D Arrays in Java. For 1-D Array, in Java, there is no difference and any of the mentioned syntaxes can be used to declare a 1-D array.

Which is legal int [] arr or int arr []?

There is no difference in these two types of array declaration. There is no such difference in between these two types of array declaration. It's just what you prefer to use, both are integer type arrays. There is no difference in functionality between both styles of declaration.


1 Answers

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

like image 177
Ming-Tang Avatar answered Oct 05 '22 16:10

Ming-Tang