What is “String args[]”? parameter in main method Java

前端 未结 17 1493
有刺的猬
有刺的猬 2020-11-21 23:58

I\'m just beginning to write programs in Java. What does the following Java code mean?

public static void main(String[] args)
  • What

17条回答
  •  青春惊慌失措
    2020-11-22 00:24

    I think it's pretty well covered by the answers above that String args[] is simply an array of string arguments you can pass to your application when you run it. For completion, I might add that it's also valid to define the method parameter passed to the main method as a variable argument (varargs) of type String:

    public static void main (String... args)

    In other words, the main method must accept either a String array (String args[]) or varargs (String... args) as a method argument. And there is no magic with the name args either. You might as well write arguments or even freddiefujiwara as shown in below e.gs.:

    public static void main (String[] arguments)

    public static void main (String[] freddiefujiwara)

提交回复
热议问题