toString(): This method is available in java.lang.StringBuilder class of Java.
Syntax:
String java.lang.StringBuilder.toString()
This method returns a string containing the characters in this sequence in the same order as this sequence.
Note: The length of the string will be the length of this sequence.
Parameters: NA
Returns: a string consisting of exactly this sequence of characters.
Exceptions: NA
For Example:
StringBuilder str = new StringBuilder("Hello World")
str.toString() = > It returns Hello World.
Approach
Java
public class ToString {public static void main(String[] args) {StringBuilder str = new StringBuilder("Hello World");System.out.println(str.toString());}}
Output:
Hello World
No comments:
Post a Comment