Saturday, 14 June 2014

codePointCount (int beginIndex, int endIndex)

public int codePointCount(int beginIndex, int endIndex)
Returns the number of Unicode code points in the specified text range of this String.

class StringCodePointCount{
 public static void main(String args[]){
  int arr[] = {65536, 65537, 65538, 65539, 65540};
  String s = new String(arr, 0, arr.length);
  
  System.out.println("String Length is " +s.length());
  System.out.print("Code point count from 0 to 10 is ");
  System.out.println(s.codePointCount(0, s.length()));
 }
}

Output
String Length is 10
Code point count from 0 to 10 is 5

1. Throws IndexOutOfBoundsException if the beginIndex is negative, or endIndex is larger than the length of this String, or beginIndex is larger than endIndex.
class StringCodePointCountIndexOut{
 public static void main(String args[]){
  int arr[] = {65536, 65537, 65538, 65539, 65540};
  String s = new String(arr, 0, arr.length);
  
  System.out.println("String Length is " +s.length());
  System.out.print("Code point count from 5 to 2 is ");
  System.out.println(s.codePointCount(5, 2));
 }
}

Output
String Length is 10
Code point count from 5 to 2 is Exception in thread "main" java.lang.IndexOutOfB
oundsException
        at java.lang.String.codePointCount(String.java:733)
        at StringCodePointCountIndexOut.main(StringCodePointCountIndexOut.java:8
)




Prevoius                                                 Next                                                 Home

No comments:

Post a Comment