Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning multiple variables from a funciton. 1

Status
Not open for further replies.

milage

Programmer
Jul 13, 2001
58
US
I can't believe that I am going to ask this but how do you return more than one variable from a method in Java? Is it the same as in C++ by passing a references to all the variables? Is so what is the syntax, could you give me a sample method declaration.

Thanks in advance.

Robert Miles

 
Well, you cannot return multiple variables using reference (if the variables are objects) like in C++. You need to send back the multiple values in an array if all are the same type or as a Vector. You can do one step further if you want type safety. Create a value-holder class, instantiate it, set the values you want to be returned in it and return that object.
 
That's annoying! Ah well, thanks for the suggestions anyhow!

Robert Miles
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top