java.util.UUID.randomUUID().toString() length

前端 未结 3 1906
刺人心
刺人心 2020-12-14 13:59

Does java.util.UUID.randomUUID().toString() length always equal to 36?

I was not able to find info on that. Here it is said only the following:

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-14 14:38

    For those like me that start googling before reading the javadoc, here the javadoc ;)

    UUID.toString

    For those that Don't know how to read a grammar tree read from Bottom to Top.
    an hexDigit is one char
    an hexOctet is 2 hexDigits = 2chars
    a node is 6 * hexOctet = 6 * 2hexdigit = 6*2 chars = 12chars
    a variant_and_sequence is 2 * hexOctet = 2 * 2hexdigit = 2*2 chars = 4chars
    a time_high_and_version is 2 * hexOctet = 2 * 2hexdigit = 2*2 chars = 4chars
    a time_mid is 2 * hexOctet = 2 * 2hexdigit = 2*2 chars = 4chars
    a time_low is 4 * hexOctet = 4* 2hexdigit = 4*2 chars = 8chars
    and finaly, a UUID is < time_low > "-" < time_mid > "-" < time_high_and_version > "-" < variant_and_sequence > "-"< node >

    = 8 chars + 1 char + 4 chars + 1 char + 4 chars + 1 char + 4 chars + 1 char + 12 chars

    = 36 chars ! 128 bit of data + 4 hyphen as stated previously

    The UUID string representation is as described by this BNF: 
    
     UUID                   =  "-"  "-"
                               "-"
                               "-"
                              
     time_low               = 4*
     time_mid               = 2*
     time_high_and_version  = 2*
     variant_and_sequence   = 2*
     node                   = 6*
     hexOctet               = 
     hexDigit               =
           "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
           | "a" | "b" | "c" | "d" | "e" | "f"
           | "A" | "B" | "C" | "D" | "E" | "F"
    

提交回复
热议问题