public class Test { public static void main(String args[]) { String s = "祝你考出好成绩!"; System.out.println(s.length()); } }
private final char value[]; /** * Returns the length of this string. * The length is equal to the number of <a href="Character.html#unicode">Unicode * code units</a> in the string. * * @return the length of the sequence of characters represented by this * object. */ public int length() { return value.length; }一个汉字两个字节,char类型两个字节。