Bug 6963115 - String.split() returns wrong result on short sequence
Ulf Zibis
Ulf.Zibis at gmx.de
Tue Oct 25 15:02:15 UTC 2011
Hi,
I do not agree to the evaluation on http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6963115 because:
> Same as the "x".split("x") case, this is a "match found" situation,
> the resulting empty string is now a "trailing empty string",
Yes, but don't forget the leading empty string.
In my understanding, the main purpose of the split() method is to parse CSV data. So IMHO user would
expect following results for .split(";"):
"abc;def;" --> { "abc", "def" }
"abc;def" --> { "abc", "def" }
"abc;;def;" --> { "abc", "", "def" }
"abc;def;;" --> { "abc", "def", "" }
";def;" --> { "", "def" }
";;def" --> { "", "", "def" }
";;" --> { "", "" }
";" --> { "" }
"" --> { "" } or even { }
The most strange in current implementation is, that if strB = strA+something,
so that strB.length() > strA.length(),
but strB.split(x).length < strA.split(x).length.
I can accept for the 1st example:
"".split("x").length = 1
... but then for the 2nd we should have
"x".split("x").length >= 1
-Ulf
More information about the core-libs-dev
mailing list