Question: I am splitting the string using `^` char. The String which I am reading, is coming from some external source. This string contains some `\n` characters.

The string may look like:

```none
Hi hello^There\nhow are\nyou doing^9987678867abc^popup

```

when I am splitting like below, why the array length is coming as `2` instead of `4`:

```
String[] st = msg[0].split("^");
st.length //giving "2" instead of "4"

```

It look like, split is ignoring after `\n`. 

How can I fix it without replacing `\n` to some other character.

Answer: 
the string parameter for split is interpreted as regular expression.
So you have to escape the char and use:

```
st.split("\\^")

```

[see this answer for more details](https://stackoverflow.com/questions/8551489/how-to-split-the-string-using-this-special-character-in-java)
If you want to split by `^` only, then 

```
String[] st = msg[0].split("\\^");

```

If I read your question correctly, you want to split by `^` and `\n` characters, so this would suffice.

```
String[] st = msg[0].split("[\\^\\\\n]");

```

This considers that `\n` literally exists as 2 characters in a string.