Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.
public final class UUID
- Object
- UUID
ImplementsComparable<UUID>, Serializable
A 128 bit identifier: its canonical text form, random (version 4) generation and name based (version 3) generation.
randomUUID() draws its bits from the platform’s secure random source
through JdkHost. Where the platform installed none it falls back to a
Random seeded from the clock, which keeps identifiers unique for every
practical purpose but NOT unpredictable; an application that uses one as
a secret should check that its platform provides secure random bytes.
nameUUIDFromBytes(byte[]) needs an MD5 digest from the platform and
throws UnsupportedOperationException where there is none. The time based
accessors (timestamp, clockSequence, node) are not provided.
Constructors
public UUID(long mostSigBits, long leastSigBits) | An identifier from its two halves. |
Methods
public static UUID randomUUID() | A new version 4 identifier; see the class description for where its randomness comes from. |
public static UUID nameUUIDFromBytes(byte[] name) | The version 3 identifier of name: its MD5 digest, with the version and variant bits set. |
public static UUID fromString(String name) | Parses the text form toString() writes: five groups of hexadecimal digits separated by -. |
public long getMostSignificantBits() | The most significant 64 bits. |
public long getLeastSignificantBits() | The least significant 64 bits. |
public int version() | The version number: 4 for one made by randomUUID(), 3 for one made by nameUUIDFromBytes(byte[]). |
public int variant() | The variant number: 2 for the IETF layout every identifier made here has. |
public String toString() | Returns a string representation of the object. |
public int hashCode() | Returns a hash code value for the object. |
public boolean equals(Object obj) | Indicates whether some other object is “equal to” this one. |
public int compareTo(UUID val) | Orders by the most significant half, then the least, each as a signed number – the order the JDK defines. |
Inherited methods
Constructor details
UUID
public UUID(long mostSigBits, long leastSigBits)Method details
randomUUID
public static UUID randomUUID()nameUUIDFromBytes
public static UUID nameUUIDFromBytes(byte[] name)name: its MD5 digest, with the version
and variant bits set.Throws
UnsupportedOperationException- if the platform has no MD5 digest
fromString
public static UUID fromString(String name)toString() writes: five groups of hexadecimal
digits separated by -. As in the JDK, a group may be shorter than
its full width, and one that is longer is not refused either: the
digits past its width are dropped, so 100000000-0-0-0-0 is the
nil UUID there and here. Only a group of more than sixteen digits,
which no long holds, is an error.Throws
IllegalArgumentException- if
nameis not in that form
getMostSignificantBits
public long getMostSignificantBits()getLeastSignificantBits
public long getLeastSignificantBits()version
public int version()randomUUID(), 3 for one made
by nameUUIDFromBytes(byte[]).variant
public int variant()toString
public String toString()hashCode
public int hashCode()equals
public boolean equals(Object obj)compareTo
public int compareTo(UUID val)Parameters
valUUID- the object to compare to this instance.
Returns
another;
a positive integer if this instance is greater than
another; 0 if this instance has the same order as
another.Throws
ClassCastException- if
anothercannot be converted into something comparable tothisinstance.