一个 Java 字符串到底有多少个字符?
来源:http://dwz.win/jqd 依照Java的文档, Java中的字符内部是以UTF-16编码方式表示的,最小值是 \u0000 ( 0 ),最大值是 \uffff ( 65535 ), 也就是一个字符以2个字节来表示, 难道Java最多只能表示 65535 个字符? char : The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or 65,535 inclusive). from The Java™ Tutorials 首先,让我们先看个例子: public class Main { public static void main(String[] args) { // 中文常见字 String s = "你好"; System.out.println("1. string length =" + s.length()); System.out.println("1. string bytes length =" + s.getBytes().length); System.out.println("1. string char length =" + s