本文共 2285 字,大约阅读时间需要 7 分钟。
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){ }
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对象的字符序列。
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)); }}
Output
输出量
D:\Programs>javac StringBufferClass.javaD:\Programs>java StringBufferClassThe result will be after implementing method is : java.util is a package
翻译自:
转载地址:http://tapzd.baihongyu.com/