Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is '...' in java? [duplicate]

Possible Duplicate:
What is the ellipsis for in this method signature?

I saw "T... elements" in java code. what does that mean? thanks!

like image 928
user437369 Avatar asked Dec 02 '22 05:12

user437369


1 Answers

It means, you can pass all T variables you want to a method.

If a method is:

public void myMethod(String... a)
{

}

You can make call with all String objects you want to that method:

myMethod("s1");
myMethod("s1", "s2");
myMethod("s1", "s2", "s3");
myMethod("s1", "s2", "s3", "s4");

Here's Java official documentation on that language feature. It was introduced in Java 5.

like image 54
Pablo Santa Cruz Avatar answered Jan 30 '23 03:01

Pablo Santa Cruz