Alex Rivera | Logout

What do three dots (...) indicate when used as a part of parameters during method definition?

Asked 2012-07-27T15:25:51.187
18

What do three dots (...) indicate when used as a part of parameters during method definition?

Also, is there any programming term for the symbol of those 3 dots?

I noticed in a code sample:

public void method1 (Animal... animal) {
// Code
}

And this method was called from 2 places. The arguments passed while calling were different in both scenarios though:

  1. Array of objects is passed as an argument to method1(Animal...)

  2. Object of class Animal passed as an argument to method1(Animal...)

So, is it something like, if you are not sure whether you will be passing a single element of an array or the entire array as an argument to the method, you use 3 dots as a part of parameters in the method definition?

Also, please let me know if there is any programming term for the symbol of those 3 dots.

Edit
Report

1 Answer

1

It means that zero or more String objects (or an array of them) may be passed as the parameter(s) for that function.

Maybe:

x("foo", "bar");
x("foo", "bar", "baz");
answered 2012-07-27T15:29:27.740

Your Answer