Java.lang.StringBuffer.codePointCount() Method
Description
The java.lang.StringBuffer.codePointCount() method returns the number of Unicode code points in the specified text range of this sequence. The text range begins at the specified beginIndex and extends to the char at index endIndex - 1. Thus the length (in chars) of the text range is endIndex - beginIndex.
Declaration
Following is the declaration for java.lang.StringBuffer.codePointCount() method
public int codePointCount(int beginIndex, int endIndex)
Parameters
beginIndex -- This is the index to the first char of the text range.
endIndex -- This is the index after the last char of the text range.
Return Value
This method returns the number of Unicode code points in the specified text range.
Exception
NA
Example
The following example shows the usage of java.lang.StringBuffer.codePointCount() method.
package com.tutorialspoint;
import java.lang.*;
public class StringBufferDemo {
public static void main(String[] args) {
StringBuffer buff = new StringBuffer("TUTORIALS");
System.out.println("buffer = " + buff);
// returns the codepoint count from index 1 to 5
int retval = buff.codePointCount(1, 5);
System.out.println("Count = " + retval);
buff = new StringBuffer("amrood admin ");
System.out.println("buffer = " + buff);
// returns the codepoint count from index 3 to 9
retval = buff.codePointCount(3, 9);
System.out.println("Count = " + retval);
}
}
Let us compile and run the above program, this will produce the following result:
buffer = TUTORIALS Count = 4 buffer = amrood admin Count = 6