I was just looking though some code and I came across this line:
stringBuffer.append("\n");
can anyone tell me what it means? Or more specifically what the "\n" part does?
Thanks
I was just looking though some code and I came across this line:
stringBuffer.append("\n");
can anyone tell me what it means? Or more specifically what the "\n" part does?
Thanks
Adds new line
marker to text that is actually in StringBuffer. Next part will be shown in the line below.
It appends a "newline" character, thus ending the current line and beginning a new line.
You can read what \n
and other characters mean in the Java tutorials:
A character preceded by a backslash (\) is an escape sequence and has special meaning to the compiler. The following table shows the Java escape sequences:
...
\n
Insert a newline in the text at this point.
\n
is a new line character. Here is an example:
System.out.print("hello\nmy\nname\nis\ntyler\n");
Outputs:
hello
my
name
is
tyler
"\n" means line breaking, in the following example the output will be
a
b
ex code:
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("a");
stringBuffer.append("\n");
stringBuffer.append("b");
System.out.println(stringBuffer.toString());