Java StringBuilder delete()方法与示例

StringBuilder类delete()方法 (StringBuilder Class delete() method)

  • delete() method is available in java.lang package.

    delete()方法在java.lang包中可用。

  • delete() method is used to delete characters in the given range of this sequence.

    delete()方法用于删除此序列给定范围内的字符。

  • In this method the deleting character starts at the given index beg_idx and reaches to the characters ends at the given end_idx ends at the given end_idx-1 and there is a certain condition when beg_idx = end_idx that means in a given range no character exists to delete.

    在此方法中,删除字符从给定索引beg_idx开始 ,到达字符终止于给定end_idx ,在给定end_idx-1结束,当beg_idx = end_idx时存在一定条件,这意味着在给定范围内不存在要删除的字符。

  • delete() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    delete()方法是一种非静态方法,仅可通过类对象访问,如果尝试使用类名访问该方法,则会收到错误消息。

  • delete() method may throw an exception at the time of assigning an index.

    delete()方法在分配索引时可能会引发异常。

    StringIndexOutOfBoundsException - This exception may throw when the beg_idx < 0 or beg_idx is greater than the length of this array sequence or larger than the end_idx.

    的StringIndexOutOfBoundsException -当beg_idx <0或beg_idx比end_idx大于这个数组序列的长度或更大的该异常可能抛出。

Syntax:

句法:

    public StringBuilder delete(int beg_idx , int end_idx);

Parameter(s):

参数:

  • int beg_idx – represents the starting index to delete.

    int beg_idx –表示要删除的起始索引。

  • int end_idx – represents the ending index to delete (but it does include this index before this index we can include).

    int end_idx –表示要删除的结束索引(但是在我们可以包含此索引之前,它确实包含此索引)。

Return value:

返回值:

The return type of this method is StringBuilder, it returns this StringBuilder object.

该方法的返回类型为StringBuilder ,它返回此StringBuilder对象。

Example:

例:

// Java program to demonstrate the example 
// of StringBuilder delete(int beg_idx , int end_idx)
// method of StringBuilder 

public class Delete {
    public static void main(String[] args) {

        // Creating an StringBuilder object
        StringBuilder st_b = new StringBuilder("Java World");

        // Display before deletion
        System.out.println("st_b = " + st_b);

        // By using delete(4,10) method is to delete all the characters
        // lies in a given range from index 4 to index 10
        st_b = st_b.delete(4, 10);

        // Display st_b after deletion
        System.out.println("st_b.delete(4,10) = " + st_b);
    }
}

Output

输出量

st_b = Java World
st_b.delete(4,10) = Java


翻译自: https://www.includehelp.com/java/stringbuilder-delete-method-with-example.aspx

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值