Why is java ` string The tochararray() ` and ‘new string (char []) methods do not accept charset encoding?

Why Java string Tochararray() and the new string (char []) methods do not accept character set encoding?

If you are using byte [], you can choose to use string GetBytes (charset) and new string (byte [], charset) specify the character set

I want to know if there is anything about char [] and charset coding. I don't understand There is nothing special in JavaDocs to explain this difference

Solution

These methods do not perform coding, they are just copies of the internal state of the string instance

Encoding is the process of converting a logical font into a digital representation, which is a series of bytes You can think of strings as representing Unicode glyph sequences The string class has an API that can access these glyphs as 32-bit code points, or as a series of 16 bit values encoded with utf-16-be (just the local internal representation of the string), or as the number of bytes in a series of selected encodings You only need to specify the encoding in the last case

Some encodings (such as UTF - 8) support all Unicode characters, while many others (such as us - ASCII) support only a small number The API based on char [] does not allow to specify different codes (utf-16-le or utf-16 with BOM), because one is enough, and promoting consistency can minimize errors caused by code mismatch

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>