Bugs 5061438 and 6253831 show that users sometimes fail to notice that the argument to String.split is a regular expression, not just a plain String. They then expect e.g. "a|b".split("|") to return strings "a" and "b". In fact it returns strings "", "a", "|", and "b", because "|" is a regular expression meaning "empty string or empty string". It would be good to add some text to both String.split methods that points out this pitfall and suggests using Pattern.quote.
###@###.### 2005-04-13 12:26:48 GMT
###@###.### 2005-04-13 12:26:48 GMT
- relates to
-
JDK-6253831 split(String regex) doesn't work with regex="|" (or = "\u007c")
-
- Closed
-
-
JDK-5061438 String.split produces unexpected output when '|' delimiter is used
-
- Closed
-