Java String Code Point toCodePointArray(String string)

Here you can find the source of toCodePointArray(String string)

Description

Transforms a String to its representative array of unicode code points.

License

Open Source License

Parameter

Parameter Description
string the string value to transform.

Return

an array of unicode code points.

Declaration

public static int[] toCodePointArray(String string) 

Method Source Code

//package com.java2s;
/**/* w  w  w  .  j  a va2  s.  co m*/
 * Copyright (c) 2011-2014 INRIA.
 * 
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any
 * later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>
 **/

public class Main {
    /**
     * Transforms a String to its representative array of unicode code points.
     * 
     * @param string
     *            the string value to transform.
     * 
     * @return an array of unicode code points.
     */
    public static int[] toCodePointArray(String string) {
        // the char array is copied from the string using toCharArray() because
        // direct access to an array is faster than indirect access through a
        // method
        char[] sarray = string.toCharArray();

        int[] result = new int[Character.codePointCount(sarray, 0, sarray.length)];

        for (int i = 0, j = 0, codePoint = 0; i < sarray.length; i += Character.charCount(codePoint)) {
            codePoint = Character.codePointAt(sarray, i);
            result[j++] = codePoint;
        }

        return result;
    }
}

Related

  1. toCodePoint(char high, char low)
  2. toCodePoint(char highSurrogate, char lowSurrogate)
  3. toCodePoint(char[] chars)
  4. toCodePointArray(final String str)
  5. toCodePoints(char[] src, int srcOff, int srcLen, int[] dest, int destOff)
  6. toCodepoints(String message)
  7. toCodePoints(String s)
  8. toCodePoints(String str)