StringBuffer toString() method in Java with Examples
public abstract String toString()Return Value: This method returns the String representing the data contained by StringBuffer Object. Below programs illustrate the StringBuffer.toString() method: Example 1:
// Java program to demonstrate
// the toString() Method.
class GFG {
public static void main(String[] args)
{
// create a StringBuffer object
// with a String pass as parameter
StringBuffer str
= new StringBuffer("GeeksForGeeks");
// print string
System.out.println("String contains = "
+ str.toString());
}
}
String contains = GeeksForGeeks
// Java program to demonstrate
// the toString() Method.
class GFG {
public static void main(String[] args)
{
// create a StringBuffer object
// with a String pass as parameter
StringBuffer str
= new StringBuffer(
"Geeks for Geeks contribute");
// print string
System.out.println("String contains = "
+ str.toString());
}
}
String contains = Geeks for Geeks contribute