Aditya
Aditya

Reputation: 1135

Difference between Java array assignments

I have been programming in Java for quite some time and this question popped up suddenly in my head.

What is the difference between writing:

int[] a = new int[SIZE];
int a[] = new int[SIZE];

Both of them seem to work fine on my machine.

Upvotes: 0

Views: 61

Answers (1)

KC Wong
KC Wong

Reputation: 2479

In your case, it's the same. But if you declare more than one variable in the same line, then there is a difference.

See: https://docs.oracle.com/javase/specs/jls/se7/html/jls-10.html

Particularly, these declarations:

short     s,         // scalar short
          aas[][];   // array of array of short
Object[]  ao,        // array of Object
          otherAo;   // array of Object

Upvotes: 6

Related Questions