fork download
  1. import java.util.Scanner;
  2. import java.util.UUID;
  3. import java.nio.ByteBuffer;
  4.  
  5. public class Main {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8. System.out.println("Enter UUID:");
  9. String input = scanner.nextLine();
  10.  
  11. try {
  12. UUID uuid = UUID.fromString(input);
  13. ByteBuffer buffer = ByteBuffer.allocate(16);
  14. buffer.putLong(uuid.getMostSignificantBits());
  15. buffer.putLong(uuid.getLeastSignificantBits());
  16. byte[] bytes = buffer.array();
  17.  
  18. System.out.println("Byte array in hex:");
  19. for (byte b : bytes) {
  20. System.out.printf("%02X ", b);
  21. }
  22. System.out.println("Invalid UUID format.");
  23. }
  24. }
  25. }
  26.  
Success #stdin #stdout 0.15s 56708KB
stdin
01020304-1011-2021-3031-414243444346
stdout
Enter UUID:
Byte array in hex:
01 02 03 04 10 11 20 21 30 31 41 42 43 44 43 46