Why does String.split need pipe delimiter to be escaped?
Because the syntax for that parameter to split is a regular expression, where in the '|'
has a special meaning of OR, and a '\|'
means a literal '|'
so the string "\\|"
means the regular expression '\|'
which means match exactly the character '|'
.
String.split
expects a regular expression argument. An unescaped |
is parsed as a regex meaning "empty string or empty string," which isn't what you mean.