您的位置:首页 > Web前端

Java StringBuffer CharSequence subSequence(int spos,int epos)方法与示例

2020-08-04 04:09 806 查看

StringBuffer类CharSequence subSequence(int spos,int epos) (StringBuffer Class CharSequence subSequence(int spos, int epos))

  • This method is available in package java.lang.StringBuffer.subSequence(int spos , int epos ).

    软件包java.lang.StringBuffer.subSequence(int spos,int epos)中提供了此方法。

  • This method is used to return a character sequence that is a substring in the given StringBuffer object and substring starts from spos(Starting position) and ends with epos(Ending position).

    此方法用于返回一个字符序列,该字符序列是给定StringBuffer对象中的子字符串,并且子字符串从spos (起始位置)开始,以epos (结束位置)结束。

  • The starting position (spos) will be the part of substring i.e. it is included in the returning substring and ending position(epos) will not be the part of substring i.e. it is excluded in the returning substring.

    起始位置( spos )将是子字符串的一部分,即它包含在返回的子字符串中,结束位置( epos )将不是子字符串的一部分,即它将被排除在返回的子字符串中。

Syntax:

句法:

CharSequence subSequence(int spos , int epos){
}
[/code]

Parameter(s):

参数:

We pass only two objects in the method of the StringBuffer i.e. spos(starting position), epos(ending position). The returning substring is in between spos and epos.

我们仅在StringBuffer方法中传递两个对象,即spos (开始位置), epos (结束位置)。 返回的子字符串在spos和epos之间。

Return value:

返回值:

The return type of this method is CharSequence that means this method returns the character sequence of the given StringBuffer object.

此方法的返回类型为CharSequence ,这意味着该方法返回给定StringBuffer对象的字符序列。

Java程序演示subSequence()方法的示例 (Java program to demonstrate example of subSequence() method)

import java.lang.StringBuffer;

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

StringBuffer sb = new StringBuffer(" java.util is a package of Java ");

// use subSequence(int spos , int epos)
// it will retrieve character sequence between
// spos and epos with the given string in the method.

// Display result after implementing subSequence(0,23)
// i.e. "java.util is a package" will be returned
// by the StringBuffer object "java.util is a package of Java"
System.out.println("The result will be after implementing method is :" + sb.subSequence(0, 23));
}
}
[/code]

Output

输出量

D:\Programs>javac StringBufferClass.java

D:\Programs>java StringBufferClass
The result will be after implementing method is : java.util is a package
[/code]

翻译自: https://www.includehelp.com/java/stringbuffer-charsequence--subsequence-int-spos-int-epos-method-with-example.aspx

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: