Here you can find the source of getLengthByByte(String str)
public static int getLengthByByte(String str)
//package com.java2s; public class Main { public static int getLengthByByte(String str) { int length = 0; if (str == null || str.length() == 0) { return length; }//from w w w . j a v a2 s . co m for (int i = 0; i < str.length(); i++) { int ascii = Character.codePointAt(str, i); if (ascii >= 0 && ascii <= 255) { length++; } else { length += 2; } } return length; } }