In this example we will show hoe to remove the contents of a StringBuffer.
Source Code
package com.beginner.examples;
public class ClearStringBufferExample {
/**
* @param args
*/
public static void main(String[] args) {
//create StringBuffer
StringBuilder sBuilder=new StringBuilder();
//Add content
sBuilder.append("I");
sBuilder.append("Love");
sBuilder.append("You");
System.out.println(sBuilder);
//clear content Method length() Is the number of characters
sBuilder.delete(0, sBuilder.capacity());
System.out.println(sBuilder);
}
}
Output:
ILoveYou