current position:Home>Java byte array and string conversion

Java byte array and string conversion

2022-02-03 00:38:19 CSDN Q & A

img

img


according to String Construction method of String(byte[] a, int startIndex, int count),
Should not be length=2 Return Chinese characters when “ Meet " Do you , But it's equal to 2 When you print it out, it's not , Only length=3 When it comes to " Meet ”
Don't Chinese characters occupy two byte codes ?




Refer to the answer 1:

GBK code , A Chinese character takes up two bytes .
UTF-16 code , Usually Chinese characters occupy two bytes ,CJKV Expand B District 、 Expand C District 、 Expand D The Chinese characters in the area occupy four bytes ( General character Unicode The scope is U+0000 to U+FFFF, The scope of these extensions is larger than U+20000, So it takes two UTF-16).
UTF-8 Coding is variable length coding , Usually Chinese characters occupy three bytes , Expand B The Chinese characters after the area occupy four bytes .




Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202030038164575.html

Random recommended