Home » Java programming language

Java StringBuffer deleteCharAt(int index) method with Example

Java StringBuffer deleteCharAt(int index) method: Here, we are going to learn about the deleteCharAt(int index) method of StringBuffer class with its syntax and example.
Submitted by Preeti Jain, on June 30, 2019

StringBuffer Class deleteCharAt(int index)

  • This method is available in package java.lang.StringBuffer.deleteCharAt(int index).
  • This method is used to delete the character at the given index in the method.
  • This method raises an exception StringIndexOutOfBoundsException if the given index is negative or greater than the length.

Syntax:

    StringBuffer deleteCharAt(int index){
    }

Parameter(s):

We can pass only one object in the method of the StringBuffer i.e. index.

Return value:

The return type of this method is StringBuffer that means this method returns a reference of this object.

Java program to demonstrate example of deleteCharAt() method

import java.lang.StringBuffer;

public class StringBufferClass {
    public static void main(String[] args) {

        StringBuffer sb = new StringBuffer(" welcome in java world ");

        // use deleteCharAt(int index) it will delete the 
        // character at the given index.

        // Display result after implementing deleteCharAt(15)

        System.out.println("The result will be after implementing method deleteCharAt(15) is :" + sb.deleteCharAt(15));

        sb = new StringBuffer("Version is : 8");

        // use deleteCharAt(int index) it will delete the character 
        // at the given index

        // Display result after implementing deleteCharAt(12)
        System.out.println("The result will be after implementing method deleteCharAt(12) is :" + sb.deleteCharAt(12));
    }
}

Output

D:\Programs>javac StringBufferClass.java

D:\Programs>java StringBufferClass
The result will be after implementing method deleteCharAt(15) is :welcome in javaworld
The result will be after implementing method deleteCharAt(12) is :Version is :8	





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.