When I use an RE, say "a*b", to split a string like "aaabxyz", I'd think only 1 part comes out, but there are 2 parts, with the first is a zero-length string. I wonder there is something missed in RE.split.
This seems to be consistent behavior with the split() method in general, specifically when a pattern match returns true on the very first character of a String instance. Since split() returns an array of Strings if this particular condition exists (the first character of a String happens to be matched by the pattern in the RE instance when split() is called) the first element in the string array will be returned as an empty String. This results in either negating any matching characters from the front of the String instance they are about to split(), or negate the empty String element from the returned array once split() has been called. If matching characters are encountered at the end of the String instance they either seem to be ignored, or removed from the array before the array is returned. Shouldn't this either be consistent, or should split() contain options for splitting on concurrent matches to yield empty String elements (so that this condition can be managed)?
If noone has any objections I will change this bug to INVALID. Grahams's seems to show its behaviour is correct. Perhaps some notes in the docs?
Sorry for the LATE additional comments! I have no objections as long as this case is documented. Taking the behavior into account when using "split()" has yielded no problems with my implementation so far (negating the first empty String element), but it would have helped if I knew it in advance.
Javadoc updated to reflect this behavior.