Question

I want to know about GUID in JAVA. GUID can contain a white space or not?

i am using following Code

import java.util.UUID;

UUID uuid = UUID.randomUUID();

String randomUUIDString = uuid.toString();

randomUUIDString can contain White Space? if yes what is chances to avoid it ?

Was it helpful?

Solution

No. From the documentation of UUID.toString()

The UUID string representation is as described by this BNF:

   UUID                   = <time_low> "-" <time_mid> "-"
                             <time_high_and_version> "-"
                             <variant_and_sequence> "-"
                             <node>
    time_low               = 4*<hexOctet>
    time_mid               = 2*<hexOctet>
    time_high_and_version  = 2*<hexOctet>
    variant_and_sequence   = 2*<hexOctet>
    node                   = 6*<hexOctet>
    hexOctet               = <hexDigit><hexDigit>
    hexDigit               =
          "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
          | "a" | "b" | "c" | "d" | "e" | "f"
          | "A" | "B" | "C" | "D" | "E" | "F"

As you can see, every character in the returned string will be a character from A-F, a-f, 0-9 or '-'.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top