I stumbled across weird behaviour of encoding/decoding string. Have a look at an example:
@Test
public void testEncoding() {
String str = "\uDD71"; // {56689}
byte[] utf16 = str.getBytes(StandardCharsets.UTF_16); // {-2, -1, -1, -3}
String utf16String = new String(utf16, StandardCharsets.UTF_16); // {65533}
assertEquals(str, utf16String);
}
I would assume this test will pass, but it is not the case. Could someone explain why the encoded and decoded string is not equal to the original one?