Convert string to Code Point Array - Android java.lang

Android examples for java.lang:String Unicode

Description

Convert string to Code Point Array

Demo Code

import android.text.TextUtils;
import java.util.ArrayList;
import java.util.Locale;

public class Main{

    public static int[] toCodePointArray(final String string) {
        final char[] characters = string.toCharArray();
        final int length = characters.length;
        final int[] codePoints = new int[Character.codePointCount(
                characters, 0, length)];
        int codePoint = Character.codePointAt(characters, 0);
        int dsti = 0;
        for (int srci = Character.charCount(codePoint); srci < length; srci += Character
                .charCount(codePoint), ++dsti) {
            codePoints[dsti] = codePoint;
            codePoint = Character.codePointAt(characters, srci);
        }//from w  ww .ja  v  a2s. c om
        codePoints[dsti] = codePoint;
        return codePoints;
    }

}

Related Tutorials