.codePointCount()

robgmerrill's avatar
Published Jul 23, 2021Updated Oct 5, 2021
Contribute to Docs

Returns the number of Unicode values in specified range of a string.

Syntax

string.codePointCount(int indexStart, int indexEnd)
  • indexStart (required): The index of the first character in the string to start counting from.
  • indexEnd (required): One more than the index of the last character in the string to stop counting at.

Example 1

Print the number of Unicode values in the string "Hello World":

class CountUnicodeValues {
public static void main(String[] args) {
String s = "Hello World";
System.out.println(s.codePointCount(0, 10));
// Output: 10
}
}

All contributors

Contribute to Docs

Learn Java on Codecademy