Can char store Chinese characters? | Java Basics

Source: Internet
Author: User

OK.

public static void Main (string[] args) {
                char c= ' Lee ';
                System.out.println (c);
                String s= "Week";
                System.out.println (s);
        }
Li
Zhou
String stores Chinese characters well understood, how char stores Chinese characters.

Char is stored by character, in English or Chinese, and is used for 2 bytes, storing Unicode characters. Range in 0-65536.
The Unicode encoding character set contains Chinese characters, so it is possible to store Chinese characters in char variables. However, if a particular character is not
is included in the Unicode encoding character set, this particular character cannot be stored in this char variable.
If you use 3 bytes with a lot of infrequently used words and take up a lot of unnecessary storage space, we use 2 bytes instead of 1 or 3 to represent the International Code of the Chinese character.
Supplementary Note:
1. Unicode encoding is fixed to occupy two bytes, so variables of type char are also occupied by two bytes. Unicode (Unified code, Universal code,
Single code) is a character encoding that is used on a computer. It sets a uniform and unique binary encoding for each character in each language,
To meet the requirements of text conversion and processing across languages and platforms. The disadvantages of traditional coding methods are:
① may correspond to different letters under different coding schemes.
② languages with large character sets may have different encoding lengths
The current version of Unicode for practical use corresponds to UCS-2, using 16-bit encoded space. That is, each character occupies 2 bytes.
2. Different looking coding occupies the same number of bytes: utf-32 Chinese is 4 bytes;
Utf-8 code in Chinese is 3 bytes, the letter is 1 bytes, because utf-8 is variable length encoding;
And gbk/gbk18030 Chinese is 2 bytes, English is 1 bytes.

Related Article

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.