| - a special character in regular expression. Use \\| instead .
I will explain why I added 2 slashes. To exit | I need to \| . However, to represent the string \| requires "\\|" , because \ itself must be escaped laterally in the string.
And, as xagyg pointed out in a comment, split will treat the parameter as a regular expression. This will not be considered a simple string.
In this case, you may be interested in learning about Pattern.quote . You can do Pattern.quote("|") . Thus, none of the characters will be considered as special.
source share