您的位置:首页 > Web前端

Java StringBuffer int codePointCount(int index1,int index 2)方法,包含示例

2020-08-04 03:07 1006 查看

StringBuffer类int codePointCount(int index1,int index 2) (StringBuffer Class int codePointCount(int index1 , int index 2))

  • This method is available in package java.lang.StringBuffer.codePointCount(int index).

    包java.lang.StringBuffer.codePointCount(int index)中提供了此方法。

  • This method is used to return the number of Unicode Codepoint at the specified range of index (i.e. it returns all the number of Unicode codepoint lies between index 1 and index 2) in the method.

    此方法用于在方法的指定索引范围内返回Unicode代码点的数量(即,它返回位于索引1和索引2之间的所有Unicode代码点的数量)。

  • Index range will start from 0 to length()-1.

    索引范围将从0到length()-1开始 。

  • This method does not raise an exception.

    此方法不会引发异常。

Syntax:

句法:

int codePointCount(int index1 , int index2){
}
[/code]

Parameter(s):

参数:

We pass two object in the method of the StringBuffer i.e index1 and index2.

我们在StringBuffer方法中传递了两个对象,即index1和index2 。

Return value:

返回值:

The return type of this method is int that means this method return the count of all Unicode codepoint lie between index1 and index2 and codepoint value is in number format.

此方法的返回类型为int ,这意味着此方法返回index1和index2之间的所有Unicode代码点的计数,并且代码点的值为数字格式。

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

import java.lang.StringBuffer;

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

StringBuffer sb = new StringBuffer("Java is a pure OOPS");

// use codePointCount(int index1 , int index 2)
// it will return the number of  Unicode codepoint lies
// between index 1 and index 2
int codepointcount = sb.codePointCount(2, 8);

// Display result after implementing codePointCount(2,8)
System.out.println("The result will be after implementing method codePointCount(2 , 8) is :" + codepointcount);

sb = new StringBuffer("Current Version of Java is 8");

// use codePointCount(int index1 , int index2)
// it will return the number of Unicode codepoint lies
// between index 1 and index 2

//Display result after implementing codePointCount(3,9)
System.out.println("The result will be after implementing method codePointCount(3,9) is :" + sb.codePointCount(3, 9));
}
}
[/code]

Output

输出量

D:\Programs>javac StringBufferClass.java

D:\Programs>java StringBufferClass
The result will be after implementing method codePointCount(2 , 8) is :6
The result will be after implementing method codePointCount(3,9) is :6
[/code]

翻译自: https://www.includehelp.com/java/stringbuffer-int-codepointcount-int-index1-int-index-2-method-with-example.aspx

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