In regex | - The reserved character used for alternation . You need to avoid this:
String out = string.split("\\|");
Notice that we used two backslashes. This is because the first one avoids the second in the Java string, so the string passed to the regex engine is \| .
source share