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

前端 未结 5 721
面向向阳花
面向向阳花 2021-01-30 07:34

How should I declare main() method in Java?

Like this:

public static void main(String[] args)
{
    System.out.println(\"foo\");
}
         


        
5条回答
  •  一整个雨季
    2021-01-30 07:59

    String... gets converted to a String[]. The main difference is that you can call a vararg method in 2 ways:

    method(a, b, c);
    method(new String[] {a, b, c});
    

    whereas you need to call a method that accepts an array like this:

    method(new String[] {a, b, c});
    

    For the main method it does not make a difference.

提交回复
热议问题