What is the correct way to create a object array in java?

43 Views Asked by At

I've seen examples such as:

Type arrayname[] = new Type[];

also as written as:

Type[] arrayname = new Type[]

I am quite confused about such expressions!

Where exactly should I put the []?

1

There are 1 best solutions below

2
On BEST ANSWER

Any of the above are allowed. All produce the same bytecode. JLS-10.2 Array Variables says (in part)

The [] may appear as part of the type at the beginning of the declaration, or as part of the declarator for a particular variable, or both.