When I try to split a string with a delimiter "|", it seems to split every single character.
This is my line which is causing the problem:
String out = myString.split("|");
In regex, |
is a reserved character used for alternation. You need to escape it:
String out = string.split("\\|");
Note that we used two backslashes. This is because the first one escapes the second one in the Java string, so the string passed to the regex engine is \|
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With