从Java中的StringBuilder中删除子字符串
为了从JavaStringBuilder对象中删除子字符串,我们使用delete()
方法。该delete()
方法从序列中删除范围内的字符。该delete()
方法有两个参数,开始和结束。字符从头到尾的索引1删除。
声明-java.lang.StringBuilder.delete()方法声明如下-
public StringBuilder delete(int start,int end)
让我们看一个示例,该示例从StringBuilder中删除子字符串。
示例
public class Example { public static void main(String[] args) { StringBuilder sb = new StringBuilder("Welcome to Java Programming"); System.out.println("Original StringBuilder Object: " + sb.toString()); sb.delete(4,10); System.out.println("New StringBuilder Object: " + sb.toString()); } }
输出结果
Original StringBuffer Object: Welcome to Java Programming New StringBuffer Object: Welc Java Programming