This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Var-args Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Var-args" Watch "Var-args" New topic


Vatsal Upadhyaya

Joined: Jul 08, 2013
Posts: 16

Can someone please explain what is var-args..??

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 10923

in a nutshell, you can say "i don't know exactly how many of THESE will be passed in, so let them pass in as many as they want and stick them into an array".

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
James X Peterson
Whizlabs Java Support
Ranch Hand

Joined: Feb 26, 2013
Posts: 158
Normal Method

public void call(int a,int b){....}

VarArg Method

public void call(int... a) {....}

The normal method above takes no more than 2 parameters of int type.
The varargs method takes as many number of parameters as you give of int type only.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13883

First search result for "java varargs" on Google: Varargs

(Note: "What is X" questions most often can be answered very quickly by searching Google for "X").

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
I agree. Here's the link:
subject: Var-args
Similar Threads
A question about the main()
Constructor Basics Doubt. K &B Pg131
public static void main(String... _)
Question about Boxing
Vararg Problem