StringBuilder deleteCharAt() in Java with Examples Last Updated : 29 Jun, 2022 Comments Improve Suggest changes Like Article Like Report The deleteCharAt(int index) method of StringBuilder class remove the character at the given index from String contained by StringBuilder. This method takes index as a parameter which represents the index of char we want to remove and returns the remaining String as StringBuilder Object. This StringBuilder is shortened by one char after application of this method. Syntax: public StringBuilder deleteCharAt(int index) Parameters: This method accepts one parameter index represents index of the character you want to remove. Return Value: This method returns this StringBuilder object after removing the character. Exception: This method throws StringIndexOutOfBoundsException if the index is less than zero, or index is larger than the length of String. Below programs demonstrate the deleteCharAt() method of StringBuilder Class: Example 1: Java // Java program to demonstrate // the deleteCharAt() Method. class GFG { public static void main(String[] args) { // create a StringBuilder object // with a String pass as parameter StringBuilder str = new StringBuilder("WelcomeGeeks"); // print string System.out.println("Before removal String = " + str.toString()); // remove the Character from index 8 StringBuilder afterRemoval = str.deleteCharAt(8); // print string after removal of Character System.out.println("After removal of character" + " at index 8 = " + afterRemoval.toString()); } } Output:Before removal String = WelcomeGeeks After removal of character at index 8 = WelcomeGeks Example 2: Java // Java program to demonstrate // the deleteCharAt() Method. class GFG { public static void main(String[] args) { // create a StringBuilder object // with a String pass as parameter StringBuilder str = new StringBuilder("GeeksforGeeks"); // print string System.out.println("Before removal String = " + str.toString()); // remove the Character from index 3 str = str.deleteCharAt(3); // print string after removal of Character System.out.println("After removal of Character" + " from index=3" + " String becomes => " + str.toString()); // remove the substring from index 5 str = str.deleteCharAt(5); // print string after removal of Character System.out.println("After removal of Character" + " from index=5" + " String becomes => " + str.toString()); } } Output:Before removal String = GeeksforGeeks After removal of Character from index=3 String becomes => GeesforGeeks After removal of Character from index=5 String becomes => GeesfrGeeks Example 3: To demonstrate IndexOutOfBoundException Java // Java program to demonstrate // exception thrown by the deleteCharAt() Method. class GFG { public static void main(String[] args) { // create a StringBuilder object // with a String pass as parameter StringBuilder str = new StringBuilder("evil dead_01"); try { // make index > length of String StringBuilder afterRemoval = str.deleteCharAt(14); } catch (Exception e) { System.out.println("Exception: " + e); } } } Output:Exception: java.lang.StringIndexOutOfBoundsException: String index out of range: 14 Reference: https://docs.oracle.com/javase/10/docs/api/java/lang/StringBuilder.html#deleteCharAt(int) Comment More infoAdvertise with us Next Article StringBuilder deleteCharAt() in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java java-basics Java-Functions Java-StringBuilder Practice Tags : Java Similar Reads StringBuilder delete() in Java with Examples The delete(int start, int end) method of StringBuilder class removes the characters starting from index start to index end-1 from String contained by StringBuilder. This method takes two indexes as a parameter first start represents index of the first character and endIndex represents index after th 3 min read StringBuilder charAt() in Java with Examples The charAt(int index) method of StringBuilder Class is used to return the character at the specified index of String contained by StringBuilder Object. The index value should lie between 0 and length()-1. Syntax: public char charAt(int index) Parameters: This method accepts one int type parameter in 3 min read StringBuffer deleteCharAt() Method in Java with Examples The Java.lang.StringBuffer.deleteCharAt() is a built-in Java method which removes the char at the specified position in this sequence. So that the sequence is reduced by 1 char. Syntax: public StringBuffer deleteCharAt(int indexpoint) Parameters : The method accepts a single parameter indexpoint of 2 min read StringBuffer delete() Method in Java with Examples The java.lang.StringBuffer.delete() is an inbuilt method in Java which is used to remove or delete the characters in a substring of this sequence. The substring starts at a specified index start_point and extends to the character at the index end_point. Syntax : public StringBuffer delete(int start_ 3 min read StringBuilder getChars() in Java with Examples The getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) method of StringBuilder class copies the characters starting at the given index:srcBegin to index:srcEnd-1 from String contained by StringBuilder into an array of char passed as parameter to function. The characters are copied from Str 3 min read Like