请问字符串解码问题
String hello = "Hello world 世界你好";
hello = new String(hello.getBytes(), "GB2312");
System.out.println(hello.length());//输出16
byte[] b=hello.getBytes("gb2312");
System.out.println(b.length);//输出20
hello = new String(hello.getBytes(), "UTF-8");
System.out.println(hello.length());//输出18
byte[] b=hello.getBytes("UTF-8");
System.out.println(b.length);//输出24
请问这个长度是怎么计算出来的,
就是第三个不好理解,字符串的长度空间是怎样计算的
16:每个字符(包括中文)长度为1,gb2312,转换成byte时,英文占一个字节中文占两个
字节,UTF-8时,英文一个字节,中文三个字节,输出24,但是长度为什么是18呢?
谢谢