Charles Bell
Posts: 519
Nickname: charles
Registered: Feb, 2002
|
|
Re: can a method return more than one value
|
Posted: Nov 15, 2002 8:00 PM
|
|
you can only return one "thing" which can be either or primitive data type such as: int, char, float, double or an array of primitive types, or an Object or an array of Objects or void which is nothing.
You can create you own class of objects to hold one or more String objects and then return the single object containing the Strings processed by your method.
It would be more straightforward in your case to just return an array of Strings such as in the following snippet:
public String[] process(String s){
String[] results = new String[2];
results[0] = s.substring(0, s.indexOf(":")); 1st part
results[1] = s.substring(s.indexOf(":")); // 2nd part
return results;
}
|
|