Here you can find the source of length(String str)
public static int length(String str)
//package com.java2s; //License from project: LGPL public class Main { public static int length(String str) { if (str == null) return 0; char[] c = str.toCharArray(); int len = 0; for (int i = 0; i < c.length; i++) { len++;//from w w w .jav a 2 s . c o m if (!isLetter(c[i])) { len++; } } return len; } private static boolean isLetter(char charStr) { int k = 0x80; return charStr / k == 0 ? true : false; } }