How to Append New Line to StringBuffer in Java


Here we may learn about how to append new line to StringBuffer with append method in Java.

Source Code

package com.beginner.examples;

public class StringBufferAppendNewLine {

	public static void main(String[] args) {
		
		//create StringBuffer.
		StringBuffer StringBuffer = new StringBuffer("This is the first line.");
		
		/*
		 * To append new line to StringBuffer in Java, use
		 * append method of StringBuffer.
		 */
		StringBuffer.append(System.getProperty("line.separator"));
		StringBuffer.append("This is second line.");
		
		System.out.println(StringBuffer);

	}

}

Output:

This is the first line.
This is second line.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments