StringBuffer Trim Java Example

StringBuffer Trim Java Example
This example shows how to trim StringBuffer object in Java using substring method.

public class JavaStringBufferTrimExample {

public static void main(String[] args) {

//create StringBuffer object
StringBuffer sbf = new StringBuffer(" Hello World ! ");

* Method 1: convert StringBuffer to string and use trim method of
* String.

String str = sbf.toString().trim();

System.out.println("StringBuffer trim: "" + str +"""""");

Want to learn quickly?
Try one of the many quizzes. More than Java 400 questions with detailed answers.

Add Comment


Facebook Fans