Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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
Posts: 484
Java jQuery Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15369
40
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
Matt Kohanek
Village Idiot
Ranch Hand
Posts: 484
Java jQuery Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is what I figured, I just wanted to be sure.
Thanks very much
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic