0

I'm interested in what is this '...' expression in some codes, for example:

public static void main(String... args){
   //code here
}

This is valid (maybe lambda, i'm not sure).

I find it in Spring's Sort file too:

public Sort(Sort.Order... orders) {
    this(Arrays.asList(orders));
}

Somebody can help me?

Rob Audenaerde
  • 19,195
  • 10
  • 76
  • 121
  • 4
    this are [varargs](http://stackoverflow.com/questions/766559/when-do-you-use-varargs-in-java) and another [SO question](http://stackoverflow.com/questions/1656901/varargs-and-the-argument) – SomeJavaGuy Sep 23 '15 at 09:01

2 Answers2

3

This idiom is not a lambda, it's called varargs (short for variable arguments) and it's there since Java 5.

The functionality allows you to take an indeterminate number of parameters of the same type (or sub-types) at the end of a method's signature, once per method signature.

The arguments can then be handled as an array of that type.

Mena
  • 47,782
  • 11
  • 87
  • 106
1

The "..." is "varargs": It accepts an arbitrary amount of String in first example and Orders in 2nd one. Those methods does also accept arrays.

dermoritz
  • 12,519
  • 25
  • 97
  • 185