0

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.

3
  • 2
    both are same , just a preference based but this int[] makes more sense at first look Commented Oct 14, 2016 at 6:44
  • I code like int[] a in java and int a[] in C. Commented Oct 14, 2016 at 6:45
  • agree with @PavneetSingh, I guess reading left to right i would easily notice that the variable after [] is referencing an array type Commented Oct 14, 2016 at 6:46

1 Answer 1

5

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
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, this was what I was looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.