Java String codePointCount() Method
You are Here:
Java String codePointCount()
The codePointCount()
method returns the number of Unicode values found between the given startIndex and endIndex in a string.
The index number starts from 0 and goes to n-1, where n is length of the string.
Note: The codePointCount()
method will include the character at the startIndex and exclude the character at the endIndex.
Example
Java Compiler
public class myClass
{
public static void main(String[] args)
{
String str = "Apple";
System.out.print(str.codePointCount(1, 3)); // 2
}
}
Output
2
Syntax
public int codePointCount(int startIndex, int endIndex)
Parameter Values
Value | Type | Explanation |
---|---|---|
startIndex | Required | Specifies the starting index number. |
endIndex | Required | Specifies the ending index number. |
Return Value
Value | Explanation |
---|---|
Number | Returns the number of Unicode values found between the given startIndex and endIndex in a string. |
Error | Returns IndexOutOfBoundsException, if startIndex is negative, or startIndex is larger than endIndex, or endindex is larger than the length of the string. |
Reminder
Hi Developers, we almost covered 90% of String functions and Interview Question on Java with examples for quick and easy learning.
We are working to cover every Single Concept in Java.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.