开发者

What is the equivalent of PHP's list() function in Java?

What is the equivalent of PHP's list() function in Ja开发者_Go百科va? For example

$matches = array('12', 'watt');
list($value, $unit) = $matches;


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 list and pass there variables value and unit. You can changes values of these variables. But the changes will be visible into the list method only. The original values of value and unit will 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜