Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

variable-argument list  RSS feed

 
srikanth arroju
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please explain the concept of variable-argument list using instance method
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A variable argument list is new in Java 5. You specify a variable argument list by placing an elipsis (...) after the type. The variable name after the type then becomes an array of that type.

So, for this method:

public double average(double... numbers) {
}

The variable numbers is of type double[].

One could then pass any number of arguments of type double to this method.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16026
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This article contains an explanation:
Using the Varargs Language Feature
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!