kapok

垃圾桶,嘿嘿,我藏的这么深你们还能找到啊,真牛!

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  455 随笔 :: 0 文章 :: 76 评论 :: 0 Trackbacks

package test;

import java.io.UnsupportedEncodingException;

/**
 * Classname :
 * ClassType :
 *
 * @version $Revision$
 * @author $author$
 */
public class HelloWorld {
    String sEnglish  = "Apple";
    String sChinese  = "苹果";
    String mixString = "Apple 苹果";

    /**
     * DOCUMENT ME!
     *
     * @param args DOCUMENT ME!
     * @throws UnsupportedEncodingException
     */
    public static void main(String[] args)
                     throws UnsupportedEncodingException {
        System.out.println("Hello, World!");

        HelloWorld hw = new HelloWorld();
        System.out.println("sEnglish String length: " + hw.sEnglish.length());
        System.out.println("sChinese String length: " + hw.sChinese.length());
        System.out.println("mixString String length: " + hw.mixString.length());
        System.out.println("********************************************************************");
        System.out.println("UTF-8 Bytes length: "
                           + hw.sEnglish.getBytes("UTF-8").length);
        System.out.println("UTF-8 Bytes length: "
                           + hw.sChinese.getBytes("UTF-8").length);
        System.out.println("UTF-8 Bytes length: "
                           + hw.mixString.getBytes("UTF-8").length);
        System.out.println("********************************************************************");
        System.out.println("GBK Bytes length: "
                           + hw.sEnglish.getBytes("GBK").length);
        System.out.println("GBK Bytes length: "
                           + hw.sChinese.getBytes("GBK").length);
        System.out.println("GBK Bytes length: "
                           + hw.mixString.getBytes("GBK").length);
        System.out.println("********************************************************************");
        System.out.println("UTF-16 Bytes length: "
                           + hw.sEnglish.getBytes("UTF-16").length);
        System.out.println("UTF-16 Bytes length: "
                           + hw.sChinese.getBytes("UTF-16").length);
        System.out.println("UTF-16 Bytes length: "
                           + hw.mixString.getBytes("UTF-16").length);
        System.out.println("********************************************************************");
        System.out.println("Unicode Bytes length: "
                           + hw.sEnglish.getBytes("Unicode").length);
        System.out.println("Unicode Bytes length: "
                           + hw.sChinese.getBytes("Unicode").length);
        System.out.println("Unicode Bytes length: "
                           + hw.mixString.getBytes("Unicode").length);
        System.out.println("********************************************************************");
        System.out.println("Default Bytes length: "
                           + hw.sEnglish.getBytes().length);
        System.out.println("Default Bytes length: "
                           + hw.sChinese.getBytes().length);
        System.out.println("Default Bytes length: "
                           + hw.mixString.getBytes().length);
    }
}


Result:


Hello, World!
sEnglish String length: 5
sChinese String length: 2
mixString String length: 8
********************************************************************
UTF-8 Bytes length: 5
UTF-8 Bytes length: 6
UTF-8 Bytes length: 12
********************************************************************
GBK Bytes length: 5
GBK Bytes length: 4
GBK Bytes length: 10
********************************************************************
UTF-16 Bytes length: 12
UTF-16 Bytes length: 6
UTF-16 Bytes length: 18
********************************************************************
Unicode Bytes length: 12
Unicode Bytes length: 6
Unicode Bytes length: 18
********************************************************************
Default Bytes length: 5
Default Bytes length: 4
Default Bytes length: 10

posted on 2005-04-12 09:46 笨笨 阅读(358) 评论(0)  编辑  收藏 所属分类: J2EEALLJ2SE

只有注册用户登录后才能发表评论。


网站导航: