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
  • 17,859
  • 8
  • 72
  • 114
  • 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
  • 46,817
  • 11
  • 84
  • 103
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
  • 11,532
  • 21
  • 93
  • 164