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