Example usage for java.lang Character codePointCount

List of usage examples for java.lang Character codePointCount

Introduction

In this page you can find the example usage for java.lang Character codePointCount.

Prototype

public static int codePointCount(char[] a, int offset, int count) 

Source Link

Document

Returns the number of Unicode code points in a subarray of the char array argument.

Usage

From source file:Main.java

public static void main(String[] args) {
    char[] c = new char[] { 'a', 'b', 'c', 'd', 'e' };

    int offset = 1, count = 3;

    int res = Character.codePointCount(c, offset, count);

    String str = "Number of Unicode code points is " + res;

    System.out.println(str);//from   w w  w  .  ja  v  a 2s  . c o m
}

From source file:Main.java

public static void main(String[] args) {
    CharSequence seq = "Hello World from java2s.com!";
    int beginIndex = 4, endIndex = 8;

    int res = Character.codePointCount(seq, beginIndex, endIndex);

    String str = "Number. of Unicode code points is " + res;

    System.out.println(str);/*w ww.  j  av  a 2s.  c  o m*/
}

From source file:jp.furplag.util.commons.StringUtils.java

/**
 * return the Array of Unicode code points in the string.
 *
 * @param str the string, may be null./*from w w  w  .  j  ava 2  s  .  c  om*/
 * @return Array of codepoints.
 */
public static int[] getCodePoints(final String str) {
    char[] chars = defaultString(str).toCharArray();
    int[] ret = new int[Character.codePointCount(chars, 0, chars.length)];
    int index = 0;
    for (int i = 0, codePoint; i < chars.length; i += Character.charCount(codePoint)) {
        codePoint = Character.codePointAt(chars, i);
        ret[index++] = codePoint;
    }

    return ret;
}