File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Var-args" Watch "Var-args" New topic


Vatsal Upadhyaya

Joined: Jul 08, 2013
Posts: 18

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

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11951

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

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 8 API documentation
I agree. Here's the link:
subject: Var-args
It's not a secret anymore!