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