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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 10905

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: 13868

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: http://aspose.com/file-tools
subject: Var-args
Similar Threads
Constructor Basics Doubt. K &B Pg131
A question about the main()
Question about Boxing
Vararg Problem
public static void main(String... _)