1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
/* Java StringBuffer append new line example This example shows how to append new line in StringBuffer in Java using append method. */ public class JavaStringBufferAppendNewLineExample { public static void main(String args[]){ //create StringBuffer object StringBuffer sbf = new StringBuffer("This is the first line."); /* * To append new line to StringBuffer in Java, use * append method of StringBuffer class. * * Different operating systems uses different escape characters to * denote new line. For example, in Windows and DOS it is rn, in Unix * it is n. * * In order to write code which works in all OS, use Java System property * line.separator instead of escape characters. */ sbf.append(System.getProperty("line.separator")); sbf.append("This is second line."); System.out.println(sbf); } } /* Output of above given StringBuffer append new line Java example would be, This is the first line. This is second line. */ |
Add Comment