Is there a difference between main(String args[])

2019-01-08 15:01发布

Is there a difference between:

public void main(String args[]) { ... } 

and

public void main(String[] args) { ... }

I don't believe so, but I am wondering.

9条回答
甜甜的少女心
2楼-- · 2019-01-08 15:35

Semantically, they are identical. However, I'd recommend using the latter syntax (String[] args) when declaring arrays. The former syntax is there mainly for compatibility with C syntax.

Since String[], as a whole, is the type of the object in Java, it's more consistent and clear not to split it up.

A similar question addresses the [] after method argument list.

查看更多
老娘就宠你
3楼-- · 2019-01-08 15:36

Although both are used to create array of String type but second one is more popular, because with that, you can create multiple String arrays simultaneously... E.g String[] a,b; Here you have created two String Arrays a and b simultaneously.

However

String a[],b; will create String array "a" and String variable(not array) b.

Hope this clarifies.

查看更多
Lonely孤独者°
4楼-- · 2019-01-08 15:38

No

They are just two style of writting

查看更多
登录 后发表回答