List of utility methods to do Char Array Create
char[] | toCharArray(CharSequence chars) to Char Array if (chars instanceof String) return ((String) chars).toCharArray(); char[] re = new char[chars.length()]; for (int i = 0; i < re.length; i++) re[i] = chars.charAt(i); return re; |
char[] | toCharArray(CharSequence charSequence) Copies the given CharSequence into a new char[] . final int numChars = charSequence.length(); char[] charArray = new char[numChars]; for (int i = 0; i < numChars; i++) { charArray[i] = charSequence.charAt(i); return charArray; |
char[] | toCharArray(CharSequence charSequence) Converts a CharSequence into a char [] array.
char[] array = new char[charSequence.length()]; for (int i = 0; i < charSequence.length(); i++) { array[i] = charSequence.charAt(i); return array; |
char[] | toCharArray(CharSequence cs) Green implementation of toCharArray. if (cs instanceof String) { return ((String) cs).toCharArray(); } else { int sz = cs.length(); char[] array = new char[cs.length()]; for (int i = 0; i < sz; i++) { array[i] = cs.charAt(i); return array; |
char[][] | toCharArray(double[][] array) to Char Array int nr = array.length; int nc = array[0].length; char[][] ret = new char[nr][nc]; for (int i = 0; i < nr; i++) { for (int j = 0; j < nc; j++) { ret[i][j] = (char) array[i][j]; return ret; |
char[] | toCharArray(final byte[] array) to Char Array return toCharArray(array, 0, array.length);
|
char[] | toCharArray(int number, int exactArrayLength) Converts the given number into a char-array. char[] charArray = null; String numberString = Integer.toString(number); char[] numberChars = numberString.toCharArray(); if (numberChars.length > exactArrayLength) { charArray = new char[exactArrayLength]; for (int i = 0; i < charArray.length; i++) { charArray[i] = numberChars[i]; } else if (numberChars.length < exactArrayLength) { charArray = new char[exactArrayLength]; int offset = exactArrayLength - numberChars.length; for (int i = 0; i < charArray.length; i++) { charArray[i] = (i < offset) ? '0' : numberChars[i - offset]; } else { charArray = numberChars; return charArray; |
char[] | toCharArray(String map) to Char Array int[] values = toIntArray(map); if (values == null) { return null; char[] chars = new char[values.length]; for (int i = 0; i < values.length; i++) { chars[i] = (char) values[i]; return chars; |
char[] | toCharArray(String s) Converts the given string into an array of characters. return s == null ? new char[] {} : s.toCharArray(); |
char[] | toCharArray(String s) toCharArray should return a new array always, however some devices might suffer a bug that allows mutating a String (serious security hole in the JVM) hence this method simulates the proper behavior if (!charArrayBugTested) { charArrayBugTested = true; if (s.toCharArray() == s.toCharArray()) { charArrayBug = true; if (charArrayBug) { char[] c = new char[s.length()]; ... |