I'm storing tons of Java UUID
into a HashMap
as row using UUID.toString()
. Since the data is huge, soon it throws OutOfMemoryError
. Now I'm thinking about a compact way to represent the UUID
, preferably something like long
, and then later I can easily reconstruct the UUID
with that long
representation. Is this possible?
A UUID is fundamentally a number, but it's a 128-bit number, which is twice the size of a java long. You could use BigInteger (which is probably no more space-efficient than storing UUIDs as strings), or you could encapsulate the UUID in an object that contains two longs — one for the first 64 bits and one for the last 64 bits.
Given the UUID 550e8400-e29b-41d4-a716-446655440000
, you would want to create two longs, one containing the number 0x550e8400e29b41d4
, and one containing the number 0xa716446655440000
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With