Java StringBuilder toString() Method
Example
Convert a StringBuilder to a String:
StringBuilder sb = new StringBuilder("Hello");
sb.append(" World");
String myStr = sb.toString();
System.out.println(myStr);
Definition and Usage
The toString() method returns the text of a StringBuilder as a String.
Use it when you need a real String, for example to use String methods like toUpperCase(), or to store the text in a String variable.
Syntax
public String toString()
Parameter Values
None.
Technical Details
| Returns: | A String with the same text as the StringBuilder. |
|---|
Related Pages
❮ StringBuilder Methods