Friday, December 25, 2015

delete() and deleteCharAt() method

delete() and deleteCharAt() method:

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

Related Posts:

  • java while loopjava while loop package javaapplication27; public class WhileloopDemo {     public static void main(String[] args) {       … Read More
  • Method with Parameter in javaMethod with Parameter in java package javaapplication27; public class MethodWithParameter {     double width;     double height;… Read More
  • Recursion Function in java:Recursion Function in java: public class Factorial {     //this is recursive function     int fact(int n){     int resu… Read More
  • Nested Loop:Nested Loop: package javaapplication27; public class NestedLoop {     public static void main(String[] args) {       &nbs… Read More
  • Do-While loop:Do-While loop: package javaapplication27; public class DowhileLoop {     public static void main(String[] args) {       &nbs… Read More

0 comments:

Post a Comment