String.split() method order of token in the returned String array

I am working on a application where I have to deal with a custom variable aVar-

String aVar = price/barcode/area1/true  // varName/varType/varScope/tracable

There may be some other attribute added to aVar seperated by a ('/'). To get varName, varType, varScope etc I have to do the following things, please see the code below -

      String[] token = aVar.split("/");  

      String varName = token[0];
      String varType = token[1];
      String varScope = token[2];
      String traceable = token[3];

Here you can see the varName is taken from token[0] which is price, varType is taken from token[1] which is 'barcode' and so on. Here I am assuming - after splitting varName always be in token[0], varType always be in token[1] and so on. Now my question is that - Does the String array returned by the split() method always contain the String token in a order by which they are appeared (price-->barcode-->area1-->true)?

I have tested this several times with some few input and found the order maintained. But I am not sure will it be ALWAYS true for a VERY LONG string.

Jon Skeet
people
quotationmark

Assuming you're actually calling String.split(String), that method's documentation includes:

This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.

That method's documentation includes:

The array returned by this method contains each substring of this string that is terminated by another substring that matches the given expression or is terminated by the end of the string. The substrings in the array are in the order in which they occur in this string. If the expression does not match any part of the input then the resulting array has just one element, namely this string.

(Emphasis mine.)

So yes, they'll be returned in order, guaranteed.

people

See more on this question at Stackoverflow