What do 3 dots next to a parameter type mean in Java?

前端 未结 12 1629
灰色年华
灰色年华 2020-11-22 00:27

What do the 3 dots following String in the following method mean?

public void myMethod(String... strings){
    // method body
}
12条回答
  •  有刺的猬
    2020-11-22 00:33

    Adding to the other well-written answers, an advantage of varagrs I found useful is that, when I call a method with array as a parameter type, it takes away the pain of creating an array; add elements and then send it. Instead, I can just call the method with as many values as I want; from zero to many.

提交回复
热议问题