温馨提示×

java中unicode转string的方法是什么

小亿
87
2024-06-05 10:09:19
栏目: 编程语言

在Java中,可以使用String类的String(byte[] bytes, Charset charset)构造函数将Unicode编码的字节数组转换为字符串。示例如下:

byte[] unicodeBytes = {0x00, 0x48, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x6C, 0x00, 0x6F};
String unicodeString = new String(unicodeBytes, StandardCharsets.UTF_16);
System.out.println(unicodeString); // 输出:Hello

另外,String类还提供了String(byte[] bytes, int offset, int length, Charset charset)构造函数,可以指定字节数组的偏移量和长度。

0