Java StringBuffer toString Example

StringBuffer class toString method example. This example shows you how to use toString method.


StringBuffer class toString method example. This example shows you how to use toString method. toString method returns a string representing the data in this sequence. A new String object is allocated and initialized to contain the character sequence currently represented by this object. This String is then returned. Subsequent changes to this sequence do not affect the contents of the String.

Here is the code
/**
 * @(#) ToString. java
 * A class representing toString method
 * @Version  01-May-2008
 @author   Rose India Team
 */

public class ToString{
    public static void main(String[] args){

        // Construct a StringBuffer object:
        StringBuffer s = new StringBuffer("Hello there");

        // Append a char to the buffer:
        s.append('!');

       // Convert to a String object and display it:
       System.out.println(s.toString());
    }
}

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US