Here you can find the source of length(String s)
public static int length(String s)
//package com.java2s; //License from project: Open Source License public class Main { public static int length(String s) { int len = 0; for (char c : s.toCharArray()) { if (c >= 0x80) { len += 2;//w w w. j a v a 2 s . c o m } else { len++; } } return len; } }