This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes dynamic parameters to java methods 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 » Beginning Java
Bookmark "dynamic parameters to java methods" Watch "dynamic parameters to java methods" New topic

dynamic parameters to java methods

Enge Chall
Ranch Hand

Joined: Nov 22, 2005
Posts: 30
How to implement the method which accepts dynamic parameters at run time.
eg: I want to invoke f1(), f1(1), f1(1, "hello"), f1(1, "hello", 200)... This is decided only at runtime.

So the qn is: is there a way to implement f1() ???

appreciate ur answers.

Not everything that counts can be counted, and not everything that can be counted counts.
Mani Ram
Ranch Hand

Joined: Mar 11, 2002
Posts: 1140
Only with JDK 5. Varargs

Quaerendo Invenietis
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Moving to Java In General (Beginner)

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Naveen K Garg
Ranch Hand

Joined: Nov 28, 2005
Posts: 105
You can also use a hashMap object as a parameter to the method and put any number of parameters in forms of key/value pair.
Enge Chall
Ranch Hand

Joined: Nov 22, 2005
Posts: 30
Thanks guys. varargs was a useful advise.
Consider Paul's rocket mass heater.
subject: dynamic parameters to java methods
Similar Threads
Array of objects/ graphics painting help
calling the overridden method in the overridding method
Pattern for Command line parameter
Why the result is 1,0
integrating iReport with my JSP Project