I need some explanation about Java String and it's encoding. Due to some task, I got a object which I parsed to String by method .toString(). In fact it was encoded in Cp1250 so my string has some wrong characters. So I decided to decode it. As far as I read many pages on the Internet, String is usually encoded with UTF-8. So I decided to get bytes from the strings encoded as UTF-8, and encode it to a String as Cp1250.
The chunk of code:
byte[] b = response.getBytes(StandardCharsets.UTF-8);
String res = new String(b, "windows-1250");
It worked partially, because it shows the proper sign, but with an additional strange one.
I tried it also with StandardCharsets.UTF-16 but it was not working.
Anyway it worked with StandardCharsets.ISO_8859_1. I don't understand why, if the String is encoded with UTF why i got a String from method .toString() encoded with ISO_8859_1?
Any explanation?