将带整数的 ArrayList 转换为 UTF-16 字符串

Convert ArrayList with Integes to UTF-16 String

我有一个包含整数值的数组列表。

看起来像83 0 97 0 109 0 112 0 108 0 101 0

而且我知道它是 UTF-16 编码。

所以我想把它转换成字符串Sample

目前,当我省略空值时,剩下的我使用:

String.valueOf(Character.toChars(codePoint));

这会导致非英语字母的编码不正确。

有谁知道如何将这样的 ArrayList 转换为正确的 UTF-16 字符串?

public String fromUTF16LE(int... bytes) {
    byte[] b = new byte[bytes.length];
    for (int i = 0; i < b.length; ++) {
        b[i] = (byte) bytes[i];
    }
    return new String(b, StandardCharsets.UTF_16LE);
}

显然整数是字节,对于 UTF-16 是小端顺序。 人们可能会检查大小是否均匀。 解码器可能用于错误处理。