How to Create StringBuffer in Java


The example aims to create and build StringBuffer with different constructors in Java.

Source Code

package com.beginner.examples;

public class CreateStringBuffer {

	public static void main(String[] args) {
		
		//Create empty StringBuffe.
		StringBuffer stringBuffer1 = new StringBuffer();
		
		//Create with the contents StringBuffe.
		StringBuffer stringBuffer2 = new StringBuffer("Hello World");
		System.out.println(stringBuffer2);
		
	}

}

Output:

Hello World
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments