6

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 ????

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

2 Comments

+1; from reading the API and the RFC, I would have expected consistent behaviour, though...
See bugs.sun.com/bugdatabase/view_bug.do?bug_id=7025832; Oracle will not fix the implementation and will probably not even admit that the Javadoc is wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.