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));
//  w w  w .  j a v  a2  s. 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.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable