What is the difference between String name[] = {}; and String [] name = {};

java

Solution

Nothing whatsoever: the two forms are identical.

`String[] var` is more natural, and generally preferred (since it more logically combines the array type with the type name). `String var[]` is in Java basically because C/C++ use that syntax, and so it is a kind of "syntax compatibility".

Note that the postfix `[]` leads to some really insane syntax features, such as the ability to write `int function()[] { return null; }`: a function returning an `int[]`.

Problem

i wrote this code in java and i was thinking about what's the difference between making this: `String [] whatever` and `String whatever []`, if someone could told me what's happening, it's better use `String [] whatever` = {} or use `String whatever[]` = {} or this it's just deprecated. ``` public class Snippet136 { public static void main(String [] args) { String names[] = {"Jhonny", "Edurardo", "Francis", "Franklin", "Freedy"}; String [] eyes_colors = { "blue", "red", "black", "green", "black"}; System.out.print("Names:"); for (String name: names) { System.out.print( " " + name ); } System.out.print("\n\nEyes colors:"); for ( String eyes_color: eyes_colors ) { System.out.print( " " + eyes_color ); } } } ```

Original source

Related problems