Java .codePointCount()

christian.dinh's avatar
Published Jul 23, 2021Updated Oct 5, 2021
Contribute to Docs

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

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
    • Beginner Friendly.
      17 hours

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

  • Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
    • Includes 6 Courses
    • With Professional Certification
    • Beginner Friendly.
      75 hours
  • Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.
    • Beginner Friendly.
      17 hours