0

Let's say I have the word "Sample". In UTF-16 BE, this is represented as 00 53 00 61 00 6D 00 70 00 6C 00 65. When I have this, I would like to convert it back to "Sample" using Java. How do I do this?

user1329572
  • 6,176
  • 5
  • 29
  • 39
serverfaces
  • 1,155
  • 4
  • 22
  • 49

1 Answers1

5

You can convert a byte sequence to a String with a specified charset using new String(array, charset)

Constructs a new String by decoding the specified array of bytes using the specified charset. The length of the new String is a function of the charset, and hence may not be equal to the length of the byte array.

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440