how to convert StringBuffer to String - Java Language Basics

Java examples for Language Basics:StringBuffer

Introduction

To convert StringBuffer to String object, use String toString() method of StringBuffer class.

Demo Code

 
public class Main {

  public static void main(String args[]) {
    StringBuffer sbf = new StringBuffer("Hello World!");

    String str = sbf.toString();//  ww w  .  java 2 s .  c  om

    System.out.println("StringBuffer to String: " + str);
  }
}

Result


Related Tutorials