Search code examples
javasemanticsarrays

Array syntax in Java: what is the significance of the [] location


String S[] = new String[3];
String[] S = new String[3];

Both ways are proper in Java. Does it mean that for every type Type[] x is the same as Type x[]?


Solution

  • The difference is if you declare multiple variables on the same line:

    String A[], B, C;
    

    would result in A being an array of Strings, whereas B and C are Strings.

    String[] A, B, C;
    

    would result in A, B and C all being arrays of Strings.