String s = System.lineSeparator();
System.out.println(s);
I try to obtain text from variable s, but why is there no text in variable s ?
Try following code on your system
for(byte b : System.lineSeparator().getBytes()){
System.out.println(b);
}
It will print either
10
OR
13
10
Here I print the ascii code for whatever I got from System.lineSeparator().
ascii code for \n is 10 and for \r is 13.
It is also given in documentation of System.lineSeparator()
On UNIX systems, it returns "\n"; on Microsoft Windows systems it returns "\r\n".
So the point is you didn't see any output because if you try to print \r or \n because \r represents line feed and \n represents next line. And you cannot see them on console. But they will have their effects in strings.
The System.lineSeparator(); returns a string that the system uses to generally separate lines in, say for example, an input from the Standard Input.
This is generally a new line character and so when you print it in your program, you will not "See" it as is.
Try using this:
String s = System.lineSeparator();
System.out.println("~~" + s + "~~");
This will help you distinguish the output. You should see something like this:
~~
~~
This output would indicate the the new line character is separating the ~~ characters in your print statement.
Hope this helps!
System.lineSeparator()returns a line separator. Surprised me too.