Is String.split () in Java a guarantee of returning an ordered array?

I am writing an application in which I receive a message that is the sequence tag1 = value1 | tag2 = value2 | tag3 = value3 etc. I want to break it around | delimiter.

After reading Javadoc, there is nothing to say that the String.split (String regex) method is guaranteed to support the original message order. I played, and everything looks fine, but I would rather not stick to this approach if I get caught later.

So, does anyone know if there are situations where the order of the array elements returned by split () can be changed from the original string? Or can someone point out any documentation that says the order will be saved?

(Apologies if this is a hoax, but I cannot find a similar question on the site.)

+3
source share
2 answers

javadoc says:

The substrings in the array are in the order in which they occur in this string.

EDIT : the above for a version with two arguments split(String regex, int limit), but a version with one argument

It works as if by calling a separation method with two arguments with a given expression and a limit argument of zero.

+16
source

I see The substrings in the array are in the order in which they occur in this string.at http://docs.oracle.com/javase/7/docs/api/java/lang/String.html ...

+2
source

All Articles