public class StringCodec extends Object implements UuidCodec<String>
The string representation, also referred as canonical textual representation, is a string of 32 hexadecimal (base-16) digits, displayed in five groups separated by hyphens, in the form 8-4-4-4-12 for a total of 36 characters (32 hexadecimal characters and 4 hyphens).
This codec decodes (parses) strings in these formats, with/without hyphens:
The encoding and decoding processes can be much faster (7x) than
UUID.toString() and UUID.fromString(String) in JDK 8.
If you prefer a string representation without hyphens, use
Base16Codec instead of StringCodec. Base16Codec can
be much faster (22x) than doing
uuid.toString().replaceAll("-", "").
| 限定符和类型 | 字段和说明 |
|---|---|
static StringCodec |
INSTANCE
A shared immutable instance.
|
| 构造器和说明 |
|---|
StringCodec() |
public static final StringCodec INSTANCE
public String encode(UUID uuid)
It can be much faster than UUID.toString() in JDK 8.
encode 在接口中 UuidCodec<String>uuid - a UUIDInvalidUuidException - if the argument is invalidpublic UUID decode(String string)
It accepts strings:
It can be much faster than UUID.fromString(String) in JDK 8.
It also can be twice as fast as UUID.fromString(String) in JDK 11.
decode 在接口中 UuidCodec<String>string - a UUID stringInvalidUuidException - if the argument is invalidCopyright © 2024. All rights reserved.