- Java.lang Package classes
- Java.lang - Home
- Java.lang - Boolean
- Java.lang - Byte
- Java.lang - Character
- Java.lang - Character.Subset
- Java.lang - Character.UnicodeBlock
- Java.lang - Class
- Java.lang - ClassLoader
- Java.lang - Compiler
- Java.lang - Double
- Java.lang - Enum
- Java.lang - Float
- Java.lang - InheritableThreadLocal
- Java.lang - Integer
- Java.lang - Long
- Java.lang - Math
- Java.lang - Number
- Java.lang - Object
- Java.lang - Package
- Java.lang - Process
- Java.lang - ProcessBuilder
- Java.lang - Runtime
- Java.lang - RuntimePermission
- Java.lang - SecurityManager
- Java.lang - Short
- Java.lang - StackTraceElement
- Java.lang - StrictMath
- Java.lang - String
- Java.lang - StringBuffer
- Java.lang - StringBuilder
- Java.lang - System
- Java.lang - Thread
- Java.lang - ThreadGroup
- Java.lang - ThreadLocal
- Java.lang - Throwable
- Java.lang - Void
- Java.lang Package extras
- Java.lang - Interfaces
- Java.lang - Errors
- Java.lang - Exceptions
- Java.lang Package Useful Resources
- Java.lang - Useful Resources
- Java.lang - Discussion
Java.lang.Character.codePointCount() Method
Description
The java.lang.Character.codePointCount(CharSequence seq, int beginIndex, int endIndex) returns the number of Unicode code points in the text range of the specified char 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 the text range count as one code point each.
Declaration
Following is the declaration for java.lang.Character.codePointCount() method
public static int codePointCount(CharSequence seq, int beginIndex, int endIndex)
Parameters
seq − the char sequence
beginIndex − the index to the first char of the text range
endIndex − the index after the last char of the text range
Return Value
This method returns the number of Unicode code points in the specified text range.
Exception
NullPointerException − if seq is null.
IndexOutOfBoundsException - if the beginIndex is negative, or endIndex is larger than the length of the given sequence, or beginIndex is larger than endIndex.
Example
The following example shows the usage of lang.Character.codePointCount() method.
package com.tutorialspoint; import java.lang.*; public class CharacterDemo { public static void main(String[] args) { // create a CharSequence seq and assign value CharSequence seq = "Hello World!"; // create and assign value to bi, ei int bi = 4, ei = 8; // create an int res int res; // assign result of codePointCount on seq to res using bi, ei res = Character.codePointCount(seq, bi, ei); String str = "No. of Unicode code points is " + res; // print res value System.out.println( str ); } }
Let us compile and run the above program, this will produce the following result −
No. of Unicode code points is 4