Java provides us to StringBuffer the ability to delete character using the method delete() and deleteCharAt(). These method are shown here:
StringBuffer delete(int startIndex,int endIndex)
StringBuffer deleteCharAt(int loc)
Here is a small program to demonstrate these method:
package stringdemo;
public class DeleteDemo {
public static void main(String[] args) {
StringBuffer s= new StringBuffer("I love you");
s.delete(2, 5);
System.out.println("After delete:"+s);
s.deleteCharAt(0);
System.out.println("After deleteCharAt:"+s);
}
}
OUTPUT:
After delete:I e you
After deleteCharAt: e you
0 comments:
Post a Comment