• Post Reply Bookmark Topic Watch Topic
  • New Topic

Parameter type foo(int ... i)  RSS feed

 
Karl Keith
Greenhorn
Posts: 2
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been programming java for quite a few years now but have never ran across this before. What does this parameter type mean, what do the dots mean? How is it different from foo(int i){}?

public void foo(int … i){}
 
Tina Smith
Ranch Hand
Posts: 208
9
Eclipse IDE Firefox Browser Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's a varargs parameter. It is equivalent to

Takes a variable number of parameters, all of type int. They are implicitly converted to an array[int] to call the method.

foo(..) could be called as follows:


Welcome to the Ranch!
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66306
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note: vararg arguments must be the last in the argument list.
 
Karl Keith
Greenhorn
Posts: 2
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!