Java – Arbitrary Number of Arguments – the 3 dots

In some Java codes, you might come across, 3 dots like this: It is known as Varargs.

foo(String... values)

With varargs, a method, function or even constructor can be passed in an arbitrary number of arguments. Varargs are useful, when developers are not sure how many of a particular type of argument will be passed to the method.

Sample Implementation of Varargs

A varargs parameter is treated as an array within the defining member. So in the body of foo we could write for example:

public void foo(String... values) {
    String[] someStrings = values;

And now, we can call the methods with an arbitrary number of arguments, either like this


or like this

foo("a", "b", "c");

Source Codes



Author: Wu Chia Chong

My main areas of interest are software architectures and software design methods, patterns, and new trends in software development.