import java.nio.charset.StandardCharsets;
class Main {
public static void main(String[] args) {
String s = "café";
byte[] data = s.getBytes(StandardCharsets.UTF_8);
// 4 chars, but 5 bytes in UTF-8
System.out.println(s.length() + " " + data.length);
System.out.println(new String(data, StandardCharsets.UTF_8));
}
}encode to UTF-8 and back