Parameter "variable ..." in methods [duplicated]

2

Good, I've come across a new style of variables when using the FileNameExtensionFilter class. The constructor that uses has 2 parameters type String only that the second is different from the ones that I already know, it supports a set of variables type String.

public void metodo(String str, String... Strs)

Could you give me information about that style of parameter?

    
asked by Asahi Sara 05.06.2016 в 01:45
source

1 answer

3

Called varargs , ... , indicates that n (multiple) parameters of type String can arrive. In this case an array of strings.

for example:

public void miMetodo(String... valores) {
...
...
}

You can call the method in different ways:

miMetodo("Asahi");

miMetodo("Asahi", "Shara");

miMetodo("Asahi", "Shara", "Elena");

More information: Varargs

    
answered by 05.06.2016 / 01:52
source