StringBuffer toString Java Example /*         StringBuffer toString Java Example         This example shows how to conve...

StringBuffer toString Java Example

02:44 PASSOVE INCOME 0 Comments

StringBuffer toString Java Example

  1. /*
  2.         StringBuffer toString Java Example
  3.         This example shows how to convert StringBuffer to String in Java using
  4.         toString method of String class.
  5. */
  6. public class JavaStringBufferToStringExample {
  7.         public static void main(String args[]){
  8.                
  9.                 //create StringBuffer object
  10.                 StringBuffer sbf = new StringBuffer("Hello World!");
  11.                
  12.                 /*
  13.                  * To convert StringBuffer to String object, use
  14.                  * String toString() method of StringBuffer class.
  15.                  */
  16.                
  17.                 String str = sbf.toString();
  18.                
  19.                 System.out.println("StringBuffer to String: " + str);
  20.         }
  21. }
  22. /*
  23. Output of above given StringBuffer to String example would be
  24. StringBuffer to String: Hello World!
  25. */

0 comments: