Both String and StringBuilder are backed by arrays and charAt() gets the value at the specified index.

Since String is immutable, it must make a defensive copy before returning the array. So it has some additional overhead. But imo, this would only be a problem for very large strings or repeated conversion of many strings to arrays. It all depends how how you are using it.

Answer from WJS on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › stringbuilder-charat-in-java-with-examples
StringBuilder charAt() in Java with Examples - GeeksforGeeks
October 15, 2018 - 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) ...
🌐
Tutorialspoint
tutorialspoint.com › java › lang › stringbuilder_charat.htm
Java StringBuilder charAt() Method
public class StringBuilderCharAt { public static void main(String args[]) { StringBuilder sb = new StringBuilder("Tutorialspoint"); int id1 = 6; int id2 = 7; System.out.println("The character at " + (id1 + id2) + " index is: " + sb.charAt(id1 + id2)); } }
🌐
Educative
educative.io › answers › what-is-stringbuildercharat-in-java
What is StringBuilder.charAt in Java?
The charAt method can be used to get the character at the specific index of the string of the StringBuilder.
🌐
BeginnersBook
beginnersbook.com › 2014 › 08 › java-stringbuilder-charat-method
Java – StringBuilder.charAt() Method
Returns the character present at the index that we pass as an argument to the charAt() method. class JavaExample{ public static void main(String[] args) { StringBuilder sb = new StringBuilder("TEST STRING"); System.out.println("String is: "+sb); for(int i=0; i<sb.length(); i++){ System.out...
🌐
GeeksforGeeks
geeksforgeeks.org › java › stringbuilder-setcharat-in-java-with-examples
StringBuilder setCharAt() in Java with Examples - GeeksforGeeks
December 19, 2025 - The setCharAt() method of the StringBuilder class is used to replace a character at a specified index with a new character.
🌐
IIT Kanpur
iitk.ac.in › esc101 › 05Aug › tutorial › java › data › getchar.html
Getting Characters by Index from a String or String Buffer
You can get the character at a particular index within a string, string buffer, or string builder by invoking the charAt accessor method. The index of the first character is 0; the index of the last is length()-1.
Find elsewhere
🌐
BeginnersBook
beginnersbook.com › 2022 › 10 › java-stringbuilder-setcharat
Java StringBuilder setCharAt()
public class JavaExample { public static void main(String[] args) { StringBuilder sb = new StringBuilder("X to Y"); System.out.println("Old Sequence: "+sb); //set first char as 'A' sb.setCharAt(0, 'A'); //set last char as 'Z' sb.setCharAt(sb.length()-1, 'Z'); System.out.println("New Sequence: "+sb); } }
🌐
TutorialKart
tutorialkart.com › java › java-stringbuilder-charat
Java StringBuilder.charAt() - Syntax & Examples
January 24, 2021 - StringBuilder.charAt() returns the char value in this sequence (StringBuilder object) at the specified index.
🌐
Tutorialspoint
tutorialspoint.com › java › lang › stringbuilder_setcharat.htm
Java StringBuilder setCharAt() Method
The Java StringBuilder setCharAt() method, is used to add/insert the character at the specified index in a StringBuilder object. The index refer to the character position in the given sequence.
🌐
IncludeHelp
includehelp.com › java › stringbuilder-charat-method-with-example.aspx
Java StringBuilder charAt() method with example
December 21, 2019 - // Java program to demonstrate the example // of char charAt(int indices) method of StringBuilder public class CharAt { public static void main(String[] args) { // Creating an StringBuilder object StringBuilder st_b = new StringBuilder("Java"); System.out.println("st_b = " + st_b); // By using charAt(1) method to display the character of // given index 1 i.e.
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.

🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › system.text.stringbuilder
StringBuilder Class (System.Text) | Microsoft Learn
using System; using System.Text; public sealed class App { static void Main() { // Create a StringBuilder that expects to hold 50 characters. // Initialize the StringBuilder with "ABC".
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › lang › StringBuilder.html
StringBuilder (Java Platform SE 7 )
Instances of StringBuilder are not safe for use by multiple threads. If such synchronization is required then it is recommended that StringBuffer be used. Since: 1.5 · See Also: StringBuffer, String, Serialized Form · clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait · charAt, length, subSequence ·
🌐
Tutorialspoint
tutorialspoint.com › java › lang › pdf › stringbuilder_charat.pdf pdf
http://www.tutorialspoint.com/java/lang/stringbuilder_charat.htm
Following is the declaration for java.lang.StringBuilder.charAt method · public char charAt(int index) Parameters · index -- This is the index of the desired char value. Return Value · This method returns the char value at the specified index. Exception · IndexOutOfBoundsException -- if ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › stringbuilder-class-in-java-with-examples
StringBuilder Class in Java - GeeksforGeeks
StringBuilder is a mutable sequence of characters provided by the java.lang package. Unlike String, its contents can be modified without creating a new object for every operation.
Published: September 1, 2026
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › StringBuilder.html
StringBuilder (Java Platform SE 8 )
July 21, 2026 - Instances of StringBuilder are not safe for use by multiple threads. If such synchronization is required then it is recommended that StringBuffer be used. Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown. Since: 1.5 · See Also: StringBuffer, String, Serialized Form · clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait · charAt, chars, codePoints, length, subSequence ·
🌐
Dot Net Perls
dotnetperls.com › stringbuilder-java
Java - StringBuilder Examples - Dot Net Perls
A for-loop can iterate over the characters in a StringBuilder. We access the length() method to get the StringBuilder's size and then use charAt() to access chars.