Java StringBuffer codePointCount() Example

Java StringBuffer codePointCount() method returns the number of Unicode code points in the specified text range of this String. The text range begins at the specified beginIndex and extends to the char at index endIndex - 1.
This method throws IndexOutOfBoundsException - if the beginIndex is negative, or endIndex is larger than the length of this String, or beginIndex is larger than the endIndex.

Java StringBuffer codePointCount() Example

public class CodePointCountExample {
 public static void main(String[] args) {
  StringBuffer buffer = new StringBuffer("javaguides");
  System.out.println("length of the string :: " + buffer.length());
  int unicode = buffer.codePointCount(0, buffer.length());
  System.out.println("the character (Unicode code point) "
    + " at the specified index is :: " + unicode);
 }
}
Output:
length of the string :: 10
the character (Unicode code point)  at the specified index is :: 10

Reference



Comments