How to convert StringBuilder to String in Java?
The StringBuilder class provides a toString() method that can be used to convert it to a String type. The usage is as follows:
StringBuilder sb = new StringBuilder("Hello");
String str = sb.toString();
In the code above, we start by creating a StringBuilder object called sb and initialize it with “Hello”. Next, we use the toString() method to convert the StringBuilder object into a String type and assign it to the variable str. Now, the variable str is a String type object.