java中StringBuffer.setCharAt()用于将字符串中指定的位置的字符替换成目标字符。
语法
public void setCharAt(int index,char ch)
输入
index //数字,指定位置索引,索引从 0 开始
ch //需要替换的字符
抛出错误
indexOutOfBoundsException异常,如果索引为负或大于或等于字符串长度。
实例
public class StringBufferSetCharAtDemo{ public static void main(String args[]){ StringBuffer buf = new StringBuffer("51Gjie"); str.setCharAt(2,'g'); System.out.println(str); } }
输出:51gjie