Java Data Type Tutorial - Java StringBuilder.setCharAt(int index, char ch)








Syntax

StringBuilder.setCharAt(int index, char ch) has the following syntax.

public void setCharAt(int index,  char ch)

Example

In the following code shows how to use StringBuilder.setCharAt(int index, char ch) method.

public class Main {
  public static void main(String args[]) {
    StringBuilder sb = new StringBuilder("java2s.com");
    System.out.println("buffer before = " + sb);
    System.out.println("charAt(1) before = " + sb.charAt(1));
//from  ww w  . j av a2 s .  c om
    sb.setCharAt(1, 'i');
    System.out.println("buffer after = " + sb);
    System.out.println("charAt(1) after = " + sb.charAt(1));

  }
}

The code above generates the following result.