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

前端 未结 17 1672
有刺的猬
有刺的猬 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:21

    String [] args is also how you declare an array of Strings in Java.

    In this method signature, the array args will be filled with values when the method is called (as the other examples here show). Since you're learning though, it's worth understanding that this args array is just like if you created one yourself in a method, as in this:

    public void foo() {
        String [] args = new String[2];
        args[0] = "hello";
        args[1] = "every";
    
        System.out.println("Output: " + args[0] + args[1]);
    
        // etc... the usage of 'args' here and in the main method is identical
    }
    

提交回复
热议问题