You do not have anything to split in the second case as you are reading line. You read a line so you read until then \n there fore you can not split by it because it was split already by reader.
As stated in documentation
Reads a line of text. A line is considered to be terminated by any one of a line feed ('\n'), a carriage return ('\r'), or a carriage return followed immediately by a linefeed.
EDIT:
For your case what you are doing wrong is probably that you copy and paste the string from the code and expect to work in the same way.
The reason why does result whole input instead of output is that out can not type \n and expect to be equal to line feed. The reality is that you pass two char \ and n. So when you confirm it with return key value that is passed to your reading from System in is
[H,i,!,\,n,H,o,w, ,a,r,e, ,u, ,d,o,i,n,g,\,n,I, ,a,m, ,g,o,o,d]
where the firs string in your example is
[H,i,!,\n,H,o,w, ,a,r,e, ,u, ,d,o,i,n,g,\n,I, ,a,m, ,g,o,o,d]
To conclude string passed as input are treated in different manner than string defined in code. They may appear to be equal by are because \ has special meaning in Java.
splitmethodl.split("\n").\nin string literal like"a\nb"then\nmeans new line, but lets say that you read text from file that containsa\nb, then\nstops being one char, but is sequence of two characters'\'and'n'so it is the same as"a\\nb"string. Your first example works because \\ in regex engine represents \ so regex is still looking for\nmetacharacter. But if you change\nin yourString lto\\nit will stop working because regex will not find new line\nbut two characters '\' and 'n'."Hi!\\nHow are u doing\\nI am good". To make things work as you want you will need to replace"\\n"with"\n". You can do it withbr.readLine().replace("\\n", "\n");