wood burning stoves 2.0*
The moose likes Java in General and the fly likes variable arguments in functions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "variable arguments in functions" Watch "variable arguments in functions" New topic
Author

variable arguments in functions

equisitive
Greenhorn

Joined: Nov 02, 2000
Posts: 4
Does anyone know if java provides for handling variable argument lists like 'C'?
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
The concept in Java is called overloading. While Java doesn't permit 'default' agruements in the parameter list, you can effectivly do this with overloading.
Example:

Hope this helps

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
equisitive
Greenhorn

Joined: Nov 02, 2000
Posts: 4
I'm not sure if you understand what I am asking. I was wondering if java has a way to handle variable arguments in method calls like C.
e.g.
printf has a signature:
const char *printf( const char *format, ... );
where '...' is a variable list of arguments where the number of variable arguments can not be known.
If I want to process a variable number of arguments of various types, in C/C++(not sure about other languages) I can declare a method like:
void foo( arg1, arg2, ... );
allowing me to process 2(arg1, arg2) to n arguments and process the n - 2 variable arguments in my method definition if I so choose. Does anyone know if Java provides for this?
Thanks
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: variable arguments in functions
 
Similar Threads
WA #1.....word association
regard on k&b book
Home loans in India - fixed or floating ?
Running two threads
Dont declare global variables in Servlet