views:

200

answers:

1

Say I have two UUID instances:

uuid1 = UUID.randomUUID();
uuid2 = UUID.randomUUID();

If those two compare such that uuid1 is less than uuid2 i.e.,

uuid1.compareTo(uuid2) // -1

is it always true that their string representations will compare to give the same result, i.e.,

uuid1.toString().compareTo(uuid2.toString()) // -1 ????
+3  A: 

In short, no. Here's a quick counter-example of two UUIDs for which the assertion does not hold:

  • b230f7ab-9420-4a3e-a684-284c609e76a5
  • 76d1f3c9-fc72-4f1a-ab48-28a858d760c5

Using the compareTo from UUID you get -1, while compareTo from the String results in 43.

Herminator
+1; from reading the API and the RFC, I would have expected consistent behaviour, though...
Christoph