I have a method which will return two strings in an array, split(str, ":", 2) to be precise.
Is there a quicker way in java to assign the two values in the array to string variables than
String[] strings = str.split(":", 2);
String string1 = strings[0];
String string2 = strings[1];
For example is there a syntax like
String<string1, string2> = str.split(":", 2);
Thanks in advance.
No, there is no such syntax in Java.
However, some other languages have such syntax. Examples include Python’s tuple unpacking, and pattern matching in many functional languages. For example, in Python you can write
or in F# you can write