Write a Java Program to Clear the StringBuffer
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
class Main { public static void main(String[] args) { // create a string buffer StringBuffer str = new StringBuffer(); // add string to string buffer str.append("Java"); str.append(" is"); str.append(" popular."); System. span style="color: #0000CC">out.println("StringBuffer: " + str); // clear the string // using delete() str.delete(0, str.length()); System.out.println("Updated StringBuffer: " + str); } } |