Java StringBuilder deleteCharAt()方法
java.lang.StringBuilder.deleteCharAt() 方法移除在此序列中的指定位置的char值。此序列是由一个字符缩短。
1 语法
public StringBuilder deleteCharAt(int index)
2 参数
index : 要删除字符的索引。
3 返回值
这个方法返回这个对象。
4 示例
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
/**
* Java StringBuilder deleteCharAt()方法
*/
import java.lang.*;
public class StringBuilderDemo {
public static void main(String[] args) {
StringBuilder str = new StringBuilder("Java lang package");
System.out.println("string = " + str);
// deleting character from index 4 to index 9
str.delete(4, 9);
System.out.println("After deletion = " + str);
str = new StringBuilder("amit");
System.out.println("string = " + str);
// deleting character at index 2
str.deleteCharAt(2);
System.out.println("After deletion = " + str);
}
}
输出结果为:
string = Java lang package
After deletion = Java package
string = amit
After deletion = amt
热门文章
优秀文章