What is the equivalent of PHP’s list() function in Java? For example
$matches = array('12', 'watt');
list($value, $unit) = $matches;
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Due to java always passes primitives by value and does not have native support of perl style lists I am afraid there is no way to do what you need.
You can write method
listand pass there variablesvalueandunit. You can changes values of these variables. But the changes will be visible into thelistmethod only. The original values ofvalueandunitwill be the same as before the call.The java-style solution for this problem is creating custom class (even inner class it does not have any sense in other contexts). Then create method that parses your string (using regex) and creates instance of the class.