aspose file tools*
The moose likes Java in General and the fly likes array needs to be returned instead of string 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 » Java in General
Bookmark "array needs to be returned instead of string" Watch "array needs to be returned instead of string" New topic
Author

array needs to be returned instead of string

vin Hari
Ranch Hand

Joined: Nov 16, 2006
Posts: 161
Hi experts,

i am in a strange situation, i have a class which is returning one value at a time and returning the string finally one at a time,
ex:

but here on one condition the list has to return 2 values so i can change that code but the return value will be array,but return type is just string
how to handle this. the sample code i want to change as.

please suggest me how to handle this.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Before we go into how to address your question as asked, let's take a step back and get the big picture. Why do you think you need to sometimes return a String and sometimes an array? What is this method's job--what does it do and what does it produce--in non-Java terms?

I can think of at least 3 different ways to do what you want, but they're basically just band-aids on a broken design.
Manoj Kumar Jain
Ranch Hand

Joined: Aug 22, 2008
Posts: 191

As I understand you query, I think you want to return 2 values from the list back to the calling function but you want to keep the return type of function as String anyways.

you can just append 2 values by some separator in a String and can return the same back. You need to parse this String containing both of the value in the calling function.

Hope I answered your query


Do not wait to strike till the iron is hot; but make it hot by striking....
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Manoj Kumar Jain wrote:As I understand you query, I think you want to return 2 values from the list back to the calling function but you want to keep the return type of function as String anyways.

you can just append 2 values by some separator in a String and can return the same back. You need to parse this String containing both of the value in the calling function.

Hope I answered your query


Yeah, that would be one of the band-aids that I'd like to avoid.

I'd prefer the OP tell us what he's trying to do, so an appropriate approach can be suggested.
Manoj Kumar Jain
Ranch Hand

Joined: Aug 22, 2008
Posts: 191

Jeff Verdegan wrote:
I can think of at least 3 different ways to do what you want, but they're basically just band-aids on a broken design.

Hey Jeff could you please tell us about the rest of 2 band-aids...

I'd prefer the OP tell us what he's trying to do, so an appropriate approach can be suggested.

Couldn't get OP??

Yes it will be better to know first what he is trying to do..
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Manoj Kumar Jain wrote:
Jeff Verdegan wrote:
I can think of at least 3 different ways to do what you want, but they're basically just band-aids on a broken design.

Hey Jeff could you please tell us about the rest of 2 band-aids...


Nope. I'm not going to promote bad practices.


Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Manoj Kumar Jain wrote:
Couldn't get OP??


Original Poster (the person who started the thread).

Or sometimes, Original Post (the first post in the thread).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: array needs to be returned instead of string