fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String str = "Olá Mundo!";
  13. String encodings[] = { "UTF-8", "UTF-16", "ISO-8859-1" };
  14. for (String encoding : encodings) {
  15. showBytes(str, encoding);
  16. }
  17. }
  18.  
  19. static void showBytes(String str, String encoding) throws Exception {
  20. System.out.print(encoding + ":");
  21. for (byte b : str.getBytes(encoding)) {
  22. System.out.printf(" %02X", b);
  23. }
  24. System.out.println();
  25. }
  26. }
Success #stdin #stdout 0.12s 36464KB
stdin
Standard input is empty
stdout
UTF-8: 4F 6C C3 A1 20 4D 75 6E 64 6F 21
UTF-16: FE FF 00 4F 00 6C 00 E1 00 20 00 4D 00 75 00 6E 00 64 00 6F 00 21
ISO-8859-1: 4F 6C E1 20 4D 75 6E 64 6F 21