Existing since Java SE 5.0 the ellipsis, also known as varargs, is one of those rarely underutilized features of Java. My guess is many novice programmers, and indeed even some experienced ones, have yet to meet Mr. Ellipsis — "…". I for one didn’t come across this elegant feature until after a year of full-time programming with Java. So what is an ellipsis?

Defining Varargs

I could not find any clear definition from the Javadocs but from what I could gather online, ellipses (also officially known as varargs (Variable Arguments)) are a Java syntax that describes an argument in a method that can take in zero or many arguments. Confusing? Let’s look at an example.

Ordinarily, if we wanted to define a method taking in two parameters of the same type, we would have something like this.

Benefits

The downside to using an array here is that first, the numbers will first have to be stored in an array either through initialization or by iterating through a loop and assigning numbers to array elements.

Although it is still true that multiple arguments must be passed in an array, the varargs feature automates and hides the process for us, giving us a more elegant solution such as the one below: