Java StringBuffer deleteCharAt()方法

java.lang.StringBuffer.deleteCharAt() 方法移除char在此序列中的指定位置。这个序列是由一个字符缩短。

1 语法

public StringBuffer deleteCharAt(int index)

2 参数

index : 这是为移除char的索引。

3 返回值

此方法返回当前对象。

4 示例 

package com.yiidian;

/**
 * 一点教程网: http://www.yiidian.com
 */
/**
 * Java StringBuffer deleteCharAt()方法
 */
import java.lang.*;

public class StringBufferDemo {

  public static void main(String[] args) {
  
    StringBuffer buff = new StringBuffer("Java lang package");
    System.out.println("buffer = " + buff);
 
    // deleting character from index 4 to index 9
    buff.delete(4, 9);
    System.out.println("After deletion = " + buff);

    buff = new StringBuffer("amit");
    System.out.println("buffer = " + buff);
    // deleting character at index 2
    buff.deleteCharAt(2);
    System.out.println("After deletion = " + buff);
  }
}

输出结果为:

buffer = Java lang package
After deletion = Java package
buffer = amit
After deletion = amt

 

热门文章

优秀文章