declaring an Array in Java

Started by
3 comments, last by Stuart_Mastrgamr 12 years, 6 months ago
when you declare an array it's common to use this convention"

int[] var = new int[10]; //bracket in front of the type


I just found out another way that compiles fine, but I dont know the difference:

int var[] = new int[10]; //brackets in front of the varable instead of the type


What's the difference between the two?
[size="4"]-- [size="4"]Stuart, [size="2"]Currently: Messing with LibGDX (Java)
aspiring video game programmer. (follow @mastrgamr)
Programming on and off since 2008 in C++, and C# (XNA).
Attending college as a Computer Science major.
Advertisement
It does the same thing.

The first one would be conventional and looks better.
The second one is to appease C programmers. It isn't used much.
As a side note, if you're planning on writing portable code, avoid using the word "var" as a symbol.

In C# and JScript, said word is used to declare a variable, type of which gets implicitly determined by its initial assigned value (as opposed to manually typing the declaration).

Niko Suni


As a side note, if you're planning on writing portable code, avoid using the word "var" as a symbol.


I realize this :P. just used as an example here.

Thanks for the replies everyone.
[size="4"]-- [size="4"]Stuart, [size="2"]Currently: Messing with LibGDX (Java)
aspiring video game programmer. (follow @mastrgamr)
Programming on and off since 2008 in C++, and C# (XNA).
Attending college as a Computer Science major.

This topic is closed to new replies.

Advertisement