Characters in JAVA are different in different encodings

Source: Internet
Author: User

*/utf-8 Chinese byte length: 6utf-16 Chinese byte length: 6utf-16be Chinese byte length: 4utf-16le Chinese byte length: 4utf-32 Chinese byte length: 8utf-32be Chinese byte length: 8utf-32le Chinese byte length: 8unicode Chinese byte length: 6GBK Chinese bytes Length: 4gb2312 Chinese byte length: 4gb18030 Chinese byte length: 4iso8859-1 Chinese byte length: 2big5 Chinese byte length: 3ASCII Chinese byte length: 2-------------------------------------- -----------*/package Com.jlsoft.demo;import Java.io.unsupportedencodingexception;public class Chinabytelength { Static String [] charset = {"Utf-8", "utf-16", "Utf-16be", "Utf-16le", "UTF-32", "Utf-32be", "Utf-32le", "Unicode", "GBK", " GB2312 "," GB18030 "," iso8859-1 "," BIG5 "," ASCII "};p ublic static void ByteLength (String charset,string Test) throws unsupportedencodingexception {System.out.println (charset+ "Chinese byte Length:" +test.getbytes (CharSet). length);} public static void Main (string[] args) throws unsupportedencodingexception {for (int i = 0; i < charset.length; i++) {B Ytelength (Charset[i], "China");}}

Work encountered, so do a code summary, the most typical UTF-8 a Chinese character bytecode length is 3, while the GBK Chinese character bytecode length is 2, English is 1.

Characters in JAVA are different in different encodings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.