Here you can find the source of toCodePointArray(String string)
Parameter | Description |
---|---|
string | the string value to transform. |
public static int[] toCodePointArray(String string)
//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; } }