Question: I am trying to split a string like: abc|aa||
When I use the regular string.split I am required to provide a regular expression.
I tried to do the following :
 string.split("|")
 string.split("\|")
 string.split("/|")
 string.split("\Q|\E")

Non of them work.....

Does anyone know how to make it work?

Answer: 
I don't know how you tried, but 

```
public static void main(String[] args) {
    String a= "abc|aa||";
    String split = Pattern.quote("|");
    System.out.println(split);
    System.out.println(Arrays.toString(a.split(split)));
}

```

prints out

```
\Q|\E
[abc, aa]

```

effectively splitting on `|`. The `\Q ... \E` is a regex quote. Anything inside it will be matched as a literal pattern.

---

```
string.split("\|"); // won't work because \| is not a valid escape sequence
string.split("/|"); // will compile, but split on / and empty space, so between each character
string.split("|");  // will compile, but split on empty space, so between each character

// true alternative to quoted solution above
 string.split("\\|") // escape the second \ which will resolve as an escaped | in the regex pattern

```
`|` is a special character for the regular expression, thus it must be escaped e.g. `\|`

The backslash `\` is a special character in Java, thus it must also be escaped

As a result, must do the following to achieve the desired effect.

```
string.split("\\|")

```