java.lang.StringBuffer codePointCount(int beginIndex,int endIndex)
Description :
This java tutorial shows how to use the codePointCount(int beginIndex,int endIndex) method of StringBuffer class under java.lang package.
The codePointCount(int beginIndex,int endIndex) 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. Unpaired surrogates within this sequence count as one code point each.
Method Syntax :
public int codePointCount(int beginIndex,int endIndex)
Parameter Input :
DataType | Parameter | Description |
---|---|---|
int | beginIndex | the index to the first char of the text range. |
int | endIndex | the index after the last char of the text range. |
Method Returns :
The codePointCount(int beginIndex,int endIndex) method simply returns the number of Unicode code points in the specified text range.
Compatibility Version :
Requires Java 1.5 and up
Java Code Example :
This java example source code demonstrates the use of codePointCount(int beginIndex,int endIndex) method of StringBuffer class. Initially the code assigns a string “javatutorialhq.com” as initial contents of the string buffer. Then we use the codePointCount(int beginIndex,int endIndex) of the StringBuffer starting at index 2 until index 5.
package com.javatutorialhq.java.examples; /* * This example source code demonstrates the use of * codePointCount(int beginIndex, int endIndex) method of StringBuffer class */ public class StringBufferCodePointCount { public static void main(String[] args) { // initialize the StringBuffer object StringBuffer sb = new StringBuffer("javatutorialhq.com"); System.out.println("Contents of buffer:" + sb); // get the codePointCount from index 2 to index 5 int beginIndex = 2; int endIndex = 5; System.out.println("CodePointCount from index " + beginIndex + " until " + endIndex + " is " + sb.codePointCount(beginIndex, endIndex)); } }
Sample Output :
Running the codePointCount(int beginIndex,int endIndex) method example source code of StringBuffer class will give you the following output
Exception Scenario :
N/A
Similar Method :
- N/A