File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Var-args

Vatsal Upadhyaya
Greenhorn

Joined: Jul 08, 2013
Posts: 18

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


Avenger
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11499
    
  16

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: 14435
    
  23

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: http://aspose.com/file-tools
 
subject: Var-args