coderolls Staff
coderolls Staff Hi 👋🏼, At coderolls we write tutorials about Java programming language and related technologies.

How To Convert StringBuilder To String In Java?

How To Convert StringBuilder To String In Java?

In this article you will see, how to convert a StringBuilder to String in Java.

Introduction

Java StringBuilder is non-synchronized update of the StringBuffer class.

Sometimes there is need to convert the StringBuilder object to the String. We can do it easily by smply invoking the toString() method.

Let see the example program below.

Java Program to convert StringBuilder to String

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/**
 * A Java program to convert StringBuilder to String
 * @author Gaurav Kukade at cderlls.com
 *
 */
public class StringBuilderToString {

	public static void main(String[] args) {
		StringBuilder stringBuilder = new StringBuilder("Hello ");
		
		stringBuilder.append("Gaurav ")
		.append("Kukade!");
		
		System.out.println("Printing strinBuilder as String: \n");
		System.out.println(stringBuilder.toString());

	}

}

Output:

1
2
3
4
Printing strinBuilder as String: 

Hello Gaurav Kukade!

Get the above code as GitHub Gist.


You can visit my YouTube channel ‘coderolls’ to find more video tutorials.

Join Newsletter
Get the latest tutorials right in your inbox. We never spam!

comments powered by Disqus