StringBuffer toString() method in Java with Examples Last Updated : 04 Dec, 2018 Comments Improve Suggest changes Like Article Like Report The toString() method of StringBuffer class is the inbuilt method used to returns a string representing the data contained by StringBuffer Object. A new String object is created and initialized to get the character sequence from this StringBuffer object and then String is returned by toString(). Subsequent changes to this sequence contained by Object do not affect the contents of the String. Syntax: 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 // 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()); } } Output: String contains = GeeksForGeeks Example 2: Java // 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()); } } Output: String contains = Geeks for Geeks contribute References: https://docs.oracle.com/javase/10/docs/api/java/lang/StringBuffer.html#toString() Comment More infoAdvertise with us Next Article StringBuffer toString() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java java-basics Java-lang package Java-Functions java-StringBuffer +1 More Practice Tags : Java Similar Reads StringBuilder toString() method in Java with Examples The toString() method of the StringBuilder class is the inbuilt method used to return a string representing the data contained by StringBuilder Object. A new String object is created and initialized to get the character sequence from this StringBuilder object and then String is returned by toString( 3 min read StringBuffer substring() method in Java with Examples In StringBuffer class, there are two types of substring method depending upon the parameters passed to it. substring(int start) The substring(int start) method of StringBuffer class is the inbuilt method used to return a substring start from index start and extends to end of this sequence. The strin 4 min read String toString() Method in java with Examples String toString() is the built-in method of java.lang which return itself a string. So here no actual conversion is performed. Since toString() method simply returns the current string without any changes, there is no need to call the string explicitly, it is usually called implicitly. Syntax : publ 1 min read ShortBuffer toString() method in Java with Examples The toString() method in java.nio.ShortBuffer is used to return a string summarizing the state of this buffer. Syntax: public String toString() Return Value:The method returns a summary string. Below are the examples to illustrate the toString() method: Program 1: Java // Java program to demonstrate 1 min read StringWriter toString() method in Java with Examples The toString() method of StringWriter Class in Java is used to get the String representation of this StringWriter instance. This method does not accept any parameter and returns the required String value. Syntax: public String toString() Parameters: This method accepts does not accepts any parameter 2 min read StringBuffer trimToSize() method in Java with Examples The trimToSize() method of StringBuffer class is the inbuilt method used to trims the capacity used for the character sequence of StringBuffer object. If the buffer used by StringBuffer object is larger than necessary to hold its current sequence of characters, then this method is called to resize t 2 min read Scanner toString() method in Java with Examples The toString() method of java.util.Scanner class returns the string representation of this Scanner. The exact format is unspecified. Syntax: public String toString() Return Value: This function returns the string representation of this scanner. Below program illustrates the above function: Program 1 1 min read Pattern toString() Method in Java with Examples toString() method of a Pattern class used to return the string representation of this pattern. This return the regular expression from which this pattern was compiled. Syntax: public String toString() Parameters: This method accepts nothing as parameter. Return value: This method returns a string re 1 min read Optional toString() method in Java with examples The toString() method of java.util.Optional class in Java is used to get the string representation of this Optional instance. Syntax: public String toString() Parameters: This method accepts nothing. Return value: This method returns the string representation of this Optional instance. Below program 1 min read Stack toString() method in Java with Example The toString() method of Java Stack is used to return a string representation of the elements of the Collection. The String representation comprises a set representation of the elements of the Collection in the order they are picked by the iterator closed in square brackets[].This method is used mai 2 min read Like