Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning String[] from a method

I want to return two values from a method stored in an array. How can I do it?
For example: The method needs to return "un" and "pwd".

like image 289
sarah Avatar asked May 29 '26 08:05

sarah


1 Answers

A tidy and Javaesque way to return multiple values is to create an object to return them in, e.g.

public class Whatever {
   public String getUn() { return m_un; }
   public String setUn(String un) { m_un = un; }
   public String getPwd() { return m_pwd; }
   public String setPwd(String pwd) { m_pwd = pwd; }
};

public Whatever getWhatever() {
   Whatever ret = new Whatever();
   ...
   ret.setPwd(...);
   ret.setUn(...);
   ...
   return ret;
}
like image 75
Will Avatar answered May 31 '26 22:05

Will



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!