Splitting a string on the double pipe(||) using String.split()
java, split
Solution
`String.split()` uses regular expressions. You need to escape the string that you want to use as divider.
Pattern has a method to do this for you, namely `Pattern.quote(String s)`.
String[] split = str.split(Pattern.quote("||"));
Problem
I'm trying to split the string with double pipe(||) being the delimiter.String looks something like this: ``` String str ="user@email1.com||user@email2.com||user@email3.com"; ``` i'm able to split it using the StringTokeniser.The javadoc says the use of this class is discouraged and instead look at String.split as option. ``` StringTokenizer token = new StringTokenizer(str, "||"); ``` The above code works fine.But not able to figure out why below string.split function not giving me expected result.. ``` String[] strArry = str.split("\\||"); ``` Where am i going wrong..?