Here you can find the source of getCharsLength(char[] chars, int specialCharsLength)
private static int getCharsLength(char[] chars, int specialCharsLength)
//package com.java2s; public class Main { private static int getCharsLength(char[] chars, int specialCharsLength) { int count = 0; int normalCharsLength = 0; for (int i = 0; i < chars.length; i++) { int specialCharLength = getSpecialCharLength(chars[i]); if (count <= specialCharsLength - specialCharLength) { count += specialCharLength; normalCharsLength++;/* w w w . j ava2 s . co m*/ } else { break; } } return normalCharsLength; } private static int getSpecialCharLength(char c) { if (isLetter(c)) { return 1; } else { return 2; } } public static boolean isLetter(char c) { int k = 0x80; return c / k == 0 ? true : false; } }