Here you can find the source of utf8StringLength(final CharSequence sequence)
public static int utf8StringLength(final CharSequence sequence)
//package com.java2s; //License from project: Apache License public class Main { public static int utf8StringLength(final CharSequence sequence) { int count = 0; for (int i = 0, len = sequence.length(); i < len; i++) { char ch = sequence.charAt(i); if (ch <= 0x7F) { count++;// w w w.ja v a 2 s . c o m } else if (ch <= 0x7FF) { count += 2; } else if (Character.isHighSurrogate(ch)) { count += 4; ++i; } else { count += 3; } } return count; } }