jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Can you have a String type method return two String values, or do I need to use String array? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Can you have a String type method return two String values, or do I need to use String array?" Watch "Can you have a String type method return two String values, or do I need to use String array?" New topic
Author

Can you have a String type method return two String values, or do I need to use String array?

Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

Just wondering if there is a way to do this. I have already found a way around my problem, but I would still like to know if I can make a method like the following return more than one String without using an array



True wisdom is in knowing you know nothing - Socrates
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

Methods can return only one value in Java. There is no built-in way to return more than one value from a method.

You could return an array, or you could write a class to contain the values you want to return:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Matt Kohanek
Village Idiot
Ranch Hand

Joined: Apr 04, 2009
Posts: 483

That is what I figured, I just wanted to be sure.
Thanks very much
 
jQuery in Action, 2nd edition
 
subject: Can you have a String type method return two String values, or do I need to use String array?