StringBuffer Reset Java Example /*         StringBuffer Reset Java Example         This example shows how to reset Strin...

StringBuffer Reset Java Example

02:43 PASSOVE INCOME 0 Comments

StringBuffer Reset Java Example

  1. /*
  2.         StringBuffer Reset Java Example
  3.         This example shows how to reset StringBuffer object to null or empty vale using delete
  4.         method.
  5. */
  6. public class StrinBufferResetExample {
  7.        
  8.         public static void main(String[] args) {
  9.                
  10.                 //create StringBuffer object
  11.                 StringBuffer sbf = new StringBuffer("Hello World!");
  12.                
  13.                 System.out.println("StringBuffer content: " + sbf) ;
  14.                
  15.                 /*
  16.                  * To reset StringBuffer to empty value, user
  17.                  * StringBuffer delete() method of StringBuffer class.
  18.                  */
  19.                
  20.                 sbf.delete(0, sbf.length());
  21.                
  22.                 System.out.println("StringBuffer content after reset:" + sbf);
  23.         }
  24. }
  25. /*
  26. Output of above given Java StringBuffer Reset example would be
  27. StringBuffer content: Hello World!
  28. StringBuffer content after reset:
  29. */

0 comments: