LEXICAL_ORDER

A Comparator that lexically orders uuids.

This comparator compares the given two 128-bit uuids bit by bit sequentially, starting from the most significant bit to the least significant. uuid a is considered less than b if, at the first position where corresponding bits of the two uuids differ, the bit in a is zero and the bit in b is one. Conversely, a is considered greater than b if, at the first differing position, the bit in a is one and the bit in b is zero. If no differing bits are found, the two uuids are considered equal.

The result of the comparison of uuids a and b by this comparator is equivalent to:

a.toString().compareTo(b.toString())

Since Kotlin

2.0

Samples

import kotlin.uuid.*

fun main() { 
   //sampleStart 
   val uuid1 = Uuid.parse("49d6d991-c780-4eb5-8585-5169c25af912")
val uuid2 = Uuid.parse("c0bac692-7208-4448-a8fe-3e3eb128db2a")
val uuid3 = Uuid.parse("49d6d991-aa92-4da0-917e-527c69621cb7")

val sortedUuids = listOf(uuid1, uuid2, uuid3).sortedWith(Uuid.LEXICAL_ORDER)

println(sortedUuids[0]) // 49d6d991-aa92-4da0-917e-527c69621cb7
println(sortedUuids[1]) // 49d6d991-c780-4eb5-8585-5169c25af912
println(sortedUuids[2]) // c0bac692-7208-4448-a8fe-3e3eb128db2a 
   //sampleEnd
}