This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Meaning of "int... j"  RSS feed

 
Suresh Rajadurai
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am preparing for Java certification, I came across a method declaration in a mock question.

public void methodX(int i, int... j)

Can anybody explain the meaning of "int... j"?

Thanks.
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at this article.
http://java.sun.com/j2se/1.5.0/docs/guide/language/varargs.html
 
Rob Spoor
Sheriff
Posts: 21087
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In short, it means "int[] i" with the difference that when calling this method, you don't need to explicitly create the array.

For example:

In the last four lines, the compiler creates an array for you. In the last case, this will be an empty array.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!