What is the difference between String [] args and String args []?

16

What is the difference between the statements String[] args and String args[] in Java?

    
asked by anonymous 06.12.2016 / 13:28

2 answers

18

None. It is only a permissiveness of language to write both ways. One ( String args[] ) is to make it easier for those who come from C or C ++ and is accustomed thus, the other ( String[] args ) is more intuitive, since the two parts of the variable type declaration are together. The first one is weird because one part of the type is in one place and the other part is next to the variable.

I think the "new" Java form, which is preferred, is a bug too, but it's what it has. The correct one would be []String . So there's a array of String , just like you have ArrayList<String> , so it has a " ArrayList of String ". String[] you have to read backwards or read strangely: "String's in an array ".

The original question was about using main() . By chance, it is being used in main() , but this has to do with declaration of variables (parameter are non-variable. If you want to know something about main() , you have a

06.12.2016 / 13:34
10

Execution works both ways with no real difference. The recommendation is to use the String[] args syntax that is most consistent with the Java typing declaration.

The first one also allows the creation of several arrays simultaneously, facilitating the use:

String[] array1, array2;
    
06.12.2016 / 13:34