What is equivalent to PHP list () function in Java?

What is equivalent to PHP list() function in Java? for instance

 $matches = array('12', 'watt'); list($value, $unit) = $matches; 
+4
source share
1 answer

Because of java, primitives by value always pass and do not have built-in support for perl style lists. I am afraid that you cannot do what you need.

You can write the list method and pass the value and unit variables there. You can change the values ​​of these variables. But the changes will only be visible in the list method. The initial values ​​of value and unit will be the same as before the call.

The solution to this problem in the Java style is to create a custom class (even the inner class does not make sense in other contexts). Then create a method that parses your string (using a regular expression) and instantiates the class.

+8
source

All Articles