字符 人们使用的记号,抽象意义上的一个符号。 '1', '中', 'a', '$', '¥', ……
字节 计算机中存储数据的单元,一个8位的二进制数,是一个很具体的存储空间。 0x01, 0x45, 0xFA, ……
public class test {
public static void main(String[] args) {
String test = "aa";
byte []bytes = test.getBytes();
int i = bytes.length;//i为字节长度
int j = test.length();//j为字符长度
System.out.println(i+" "+j);
}
}
//output:2 2
public class test {
public static void main(String[] args) {
String test = "中国";
byte []bytes = test.getBytes();
int i = bytes.length;//i为字节长度
int j = test.length();//j为字符长度
System.out.println(i+" "+j);
}
}
//output:4 2
i是否等于j就可判断是纯中文或纯英语