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. final byte[] test = new byte[8];
  12. test[0] = (byte) 0xF0;
  13. test[1] = (byte) 0x9F;
  14. test[2] = (byte) 0x87;
  15. test[3] = (byte) 0xB7;
  16. test[4] = (byte) 0xF0;
  17. test[5] = (byte) 0x9F;
  18. test[6] = (byte) 0x87;
  19. test[7] = (byte) 0xBA;
  20.  
  21. final String input = "0xF0 0x9F 0x87 0xB7 0xF0 0x9F 0x87 0xBA";
  22. final String[] inputItems = input.trim().split(" ");
  23. final byte[] emojiByte = new byte[inputItems.length];
  24. for (int i = 0; i < inputItems.length-1; i++) {
  25. emojiByte[i] = (byte) Integer.parseInt(inputItems[i+1].replace("0x", ""), 16);
  26. }
  27. System.out.println(Arrays.toString(test));
  28. System.out.println(Arrays.toString(emojiByte));
  29. }
  30. }
Success #stdin #stdout 0.1s 28096KB
stdin
Standard input is empty
stdout
[-16, -97, -121, -73, -16, -97, -121, -70]
[-97, -121, -73, -16, -97, -121, -70, 0]