Use the codePointCount()
method in the main method
In the main()
method, we will use the codePointCount()
method to find the total Unicode code point count of the sub-array of the specified char array.
public class CharacterCodepointCount {
public static void main(String[] args) {
char[] ch1 = new char[] { 'j', 'a', 'v', 'a', '1', '2', '3' };
int offset1 = 0, count1 = 3;
int r1 = codePointCount(ch1, offset1, count1);
System.out.println("The number of Unicode code points in the subarray is: " + r1);
String s1 = "Hello World";
int offset2 = 2, count2 = 4;
int r2 = s1.codePointCount(offset2, count2);
System.out.println("The number of Unicode code points in the subarray is: " + r2);
}
public static int codePointCount(char[] a, int offset, int count) {
return Character.codePointCount(a, offset, count);
}
}
In the above code, we have created two arrays of characters and used them as parameters to the codePointCount()
method. Then we printed out the total Unicode code point count of the sub-array of the specified char array using the println()
method.