Why is it that in the following, the output is [] and not [1]?
[]
[1]
String input=\"1|2|3\"; String[] values= input.split(\"|\"); System.
The split method receives a regex as a parameter. The pipe is a reserved character with its own purpose (it means or).
split
or
You can either escape it ("\\|") or, if you're in Java 1.5+ you can use Pattern.quote("|") like this:
"\\|"
Pattern.quote("|")
input.split(Pattern.quote("|"));