Home >>Java String Methods >Java String codePointCount() Method

Java String codePointCount() Method

Java String codePointCount() Method

The codePointCount() method in Java String is used to returns the number of Unicode values found in a string.

You can also use the parameters startIndex and endIndex to specify where to begin and end the search.

Syntax

public int codePointCount(int startIndex, int endIndex)

Parameter

startIndex -This parameter is used to specifies an int value, to representing the index to the first character in the string

endIndex - It is used to representing an int value, the index after the last character in the string

Returns

It is used to represents an int value at the number of Unicode values found in a string

Throws

IndexOutOfBoundsException - If startIndex is negative or endindex greater than the string length, or startIndex greater than endIndex

Java String codePointBefore() method example 1

public class MyClass
 {
  public static void main(String[] args) 
  {
    String strln1 = "Phptpoint";
    int result = strln1.codePointCount(0, 8);
    System.out.println(result);
  }
}


8

No Sidebar ads