You have to take in to consideration the 2-byte Byte-Order-Marks for UTF-16?
Your first 2 bytes will be either: FE FF
or FF FE
depending on whether you are on Big or Little endian machine. You should check...
I did, and it's [-2, -1, 0, 65, 0, 66]
.
You should also consider that the String values do not take this extra space in memory, only when the String is encoded as byte[]
will the byte-order-mark be added.... The String AB
will use char[2]
in memory until it is byte-encoded as byte[6]
.