Convert StringBuilder To String

 In this example firstly create a string builder and then convert it to string using toString() method.

package com.javapro.string;

public class StringBuilderDemo {

public static void main(String[] args) {
StringBuilder data=new StringBuilder(“Hi”);
data.append(” How Are”);
data.append(” You”);
System.out.println(“data=”+data);

String str=data.toString();

System.out.println(“str=”+str);
}

}

Leave a Reply

Your email address will not be published. Required fields are marked *

4 + 2 =