🌐
Codecademy
codecademy.com › docs › java › stringbuilder › .deletecharat()
Java | StringBuilder | .deleteCharAt() | Codecademy
August 22, 2022 - The .deleteCharAt() method removes the character at the specified index from the contents of a StringBuilder and returns the modified object.
🌐
GeeksforGeeks
geeksforgeeks.org › java › stringbuilder-deletecharat-in-java-with-examples
StringBuilder deleteCharAt() in Java with Examples - GeeksforGeeks
January 9, 2026 - The deleteCharAt(int index) method of Java's StringBuilder class is used to remove a character at a specified position in a string.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › stringbuilder_deletecharat.htm
Java StringBuilder deleteCharAt() Method
public class StringBuilderDemo { public static void main(String[] args) { //create an object of the StringBuilder StringBuilder sb = new StringBuilder("Java lang package"); System.out.println("Before deletion the string is: " + sb); //initialize the index value int index = 3; System.out.println("The given index value is: " + index); //using the deleteCharAt() method System.out.println("After deletion the character at the specified index " + index + " index is: " + sb.deleteCharAt(index)); } }
🌐
BeginnersBook
beginnersbook.com › 2022 › 10 › java-stringbuilder-deletecharat
Java StringBuilder deleteCharAt()
October 5, 2022 - public StringBuilder deleteCharAt(int index): This method deletes the character present at the specified index.
🌐
Javatpoint
javatpoint.com › java-stringbuilder-deletecharat-method
Java StringBuilder deleteCharAt() Method with Examples - Javatpoint
Java StringBuilder deleteCharAt() Method with Examples on append(), capacity(), charAt(), codePointAt(), indexOf(), codePointBefore(), codePointCount(), delete(), deleteCharAt(), ensureCapacity(), getChars(), insert(), lastIndexOf(), length(), replace(), setCharAt(), setLength() etc.
🌐
Java Guides
javaguides.net › 2024 › 06 › java-stringbuilder-deletecharat-method.html
Java StringBuilder deleteCharAt() Method
June 10, 2024 - The deleteCharAt method can be used to remove a character at a specific index from a StringBuilder object.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › StringBuilder.html
StringBuilder (Java Platform SE 8 )
July 21, 2026 - public StringBuilder deleteCharAt(int index) Removes the char at the specified position in this sequence. This sequence is shortened by one char. Note: If the character at the given index is a supplementary character, this method does not remove the entire character.
🌐
TutorialKart
tutorialkart.com › java › java-stringbuilder-deletecharat
Java StringBuilder.deleteCharAt() - Syntax & Examples
January 24, 2021 - StringBuilder.deleteCharAt() removes the char at the specified position in this StringBuilder sequence.
Find elsewhere
🌐
Kotlin
kotlinlang.org › api › core › kotlin-stdlib › kotlin.text › delete-char-at.html
deleteCharAt | Core API – Kotlin Programming Language
inline fun StringBuilder. ... deleteAt(index) Content copied to clipboard · Removes the character at the specified index from this string builder and returns this instance....
🌐
Tutorialspoint
tutorialspoint.com › java › lang › pdf › stringbuilder_deletecharat.pdf pdf
http://www.tutorialspoint.com/java/lang/stringbuilder_deletecharat.htm
Following is the declaration for java.lang.StringBuilder.deleteCharAt method · public StringBuilder deleteCharAt(int index) Parameters · index -- This is the index of char to remove. Return Value · This method returns this object. Exception · StringIndexOutOfBoundsException -- if the index is negative or greater than or equal to ·
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › lang › StringBuilder.html
StringBuilder (Java Platform SE 7 )
public StringBuilder deleteCharAt(int index) Removes the char at the specified position in this sequence. This sequence is shortened by one char. Note: If the character at the given index is a supplementary character, this method does not remove the entire character.
🌐
Oracle
docs.oracle.com › javase › 6 › docs › api › java › lang › StringBuilder.html
StringBuilder (Java Platform SE 6)
public StringBuilder deleteCharAt(int index) Removes the char at the specified position in this sequence. This sequence is shortened by one char. Note: If the character at the given index is a supplementary character, this method does not remove the entire character.
🌐
Blogger
javahungry.blogspot.com › 2022 › 04 › stringbuilder-delete-last-character.html
Java Stringbuilder delete last character [2 ways] | Java Hungry
According to Oracle docs, we can easily delete the character at any index of the StringBuilder object using the deleteCharAt() method.
🌐
Codemia
codemia.io › home › knowledge hub › remove last character of a stringbuilder?
Remove last character of a StringBuilder? | Codemia
January 26, 2025 - StringBuilder sb = new StringBuilder("Hello World!"); sb.deleteCharAt(sb.length() - 1); // Removes the last character System.out.println(sb.toString()); // Outputs "Hello World" This method directly modifies the StringBuilder object and does not return a new one.
Top answer
1 of 6
50

For String, StringBuffer, and StringBuilder, charAt() is a constant-time operation.

For StringBuffer and StringBuilder, deleteCharAt() is a linear-time operation.

StringBuffer and StringBuilder have very similar performance characteristics. The primary difference is that the former is synchronized (so is thread-safe) while the latter is not.

2 of 6
30

Let us just look at the corresponding actual java implementation(only relevant code) for each of these methods in turn. That itself will answer about their efficiency.

String.charAt :

public char charAt(int index) {
    if ((index < 0) || (index >= value.length)) {
        throw new StringIndexOutOfBoundsException(index);
    }
    return value[index];
}

As we can see, it is just a single array access which is a constant time operation.

StringBuffer.charAt :

public synchronized char charAt(int index) {
  if ((index < 0) || (index >= count))
    throw new StringIndexOutOfBoundsException(index);
  return value[index];
}

Again, single array access, so a constant time operation.

StringBuilder.charAt :

public char charAt(int index) {
    if ((index < 0) || (index >= count))
        throw new StringIndexOutOfBoundsException(index);
    return value[index];
}

Again, single array access, so a constant time operation. Even though all these three methods look same, there are some minor differences. For example, only StringBuffer.charAt method is synchronized but not other methods. Similarly if check is slightly different for String.charAt (guess why?). Closer look at these method implementations itself give us other minor differences among them.

Now, let us look at deleteCharAt implementations.

String does not have deleteCharAt method. The reason might be it is an immutable object. So exposing an API which explicitly indicates that this method modifies the object is not probably a good idea.

Both StringBuffer and StringBuilder are subclasses of AbstractStringBuilder. The deleteCharAt method of these two classes is delegating the implementation to its parent class itself.

StringBuffer.deleteCharAt :

  public synchronized StringBuffer deleteCharAt(int index) {
        super.deleteCharAt(index);
        return this;
    }

StringBuilder.deleteCharAt :

 public StringBuilder deleteCharAt(int index) {
        super.deleteCharAt(index);
        return this;
    }

AbstractStringBuilder.deleteCharAt :

  public AbstractStringBuilder deleteCharAt(int index) {
        if ((index < 0) || (index >= count))
            throw new StringIndexOutOfBoundsException(index);
        System.arraycopy(value, index+1, value, index, count-index-1);
        count--;
        return this;
    }

A closer look at AbstractStringBuilder.deleteCharAt method reveals that it is actually calling System.arraycopy. This can be O(N) in worst case. So deleteChatAt method is O(N) time complexity.