Java中文字节长度

来源:互联网 发布:mac os x.dmg原版镜像 编辑:程序博客网 时间:2024/06/05 16:10

中文的字节编码长度跟其本身长度是不一样的,一般来说,字节码长度是本身长度的一倍。(此处有待证实)

其他英文数字的字节码长度跟本身长度是一样的。

/*

 * 32  16

 * 11  11

 */

public class GBK_Length {

 

    public static void main(String args[]){

        String str = "我是一名中国人!你呢?也是中国人";

        String str0 = "Hello World";

        System.out.println(str.getBytes().length +"  "+str.length());

        System.out.print(str0.getBytes().length+"  "+str0.length());

    }

}

原创粉丝点击