Java String codePointCount Example
String class codePointCount method example
String class codePointCount method example:- This example shows how to use codePointCount method. this method gives an integer which specifies the number of character Unicode codes which will be generated if required by the method under the defined range inside the parentheses of the method.
Here is the code:-
/**
* @(#) CodePointCountString.java
* CodePointCountString class demonstrates the working of codePointCount() method of String class of lang package
* @version 13-May-2008
* @author Rose India Team
*/
public class CodePointCountString {
public static void main(String args[]){
String str = "Professor you got to stop cerebro now ";
//method count the indexes to the defined range
//it starts at first argument index in its count ignoring the secong argument index
int numberTotal = str.codePointCount(0, 1);
System.out.println(" ");
System.out.println(numberTotal + " one is generated because method count the first argument index up to before the second argument");
System.out.println(" ");
System.out.println("Similarly");
System.out.println(" ");
System.out.println(str.codePointCount(0, 2) + " ----has range 0 and 2 which means method has got unicode number codes of two characters only");
System.out.println(" ");
System.out.println(str.codePointCount(0, 3) + " ----has range 0 and 3 which means method has got unicode number codes of three characters only");
System.out.println(" ");
System.out.println(str.codePointCount(5, 9) + " ----This means four Unicode number Images of characters at indexes under consideration have been defined by the method under range 5 to 9");
}
} |
Output of the program:-
1 one is generated because method count the first argument index up to before the second argument
Similarly
2 ----has range 0 and 2 which means method has got unicode number codes of two characters only
3 ----has range 0 and 3 which means method has got unicode number codes of three characters only
4 ----This means four Unicode number Images of characters at indexes under consideration have been defined by the method under range 5 to 9
|
|