File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Soft Skills this week in the Jobs Discussion 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: 14430
    
  23

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 8 API documentation
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can you have a String type method return two String values, or do I need to use String array?