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








Syntax

StringBuffer.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 StringBuffer.setCharAt(int index, char ch) method.

 
public class Main {
  public static void main(String args[]) {
    StringBuffer sb = new StringBuffer("java2s.com");
    System.out.println("buffer before = " + sb);
    System.out.println("charAt(1) before = " + sb.charAt(1));
/*from ww  w  . j a v  a  2s  .  co m*/
    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.