UUID in Kotlin

Kotlin UUID Generator

On the JVM and Android, Kotlin gets UUIDs from java.util.UUID — the same class Java uses, with no wrapper needed.

JVM and Androidjava.util.UUIDMultiplatform wrapper

Generated locally with the Web Crypto API — nothing leaves your browser.

Generating UUIDs in Kotlin

How to generate

  1. Press Generate UUID above to mint a value in this browser — nothing is sent anywhere.
  2. Copy one value with Copy, or set How many and use Copy all for a fixture list.
  3. Switch Version if your code needs v7 instead of the v4 default, and turn on Formatting to match your stack's conventions.

Use Cases

How Kotlin UUID Generator Compares

UUID.randomUUID()JVM and Android, v4, CSPRNG-backed
uuid-creatorLibrary; adds time-ordered v7 for JVM projects
expect/actual wrapperOne API across JVM, Native and JS targets

Code Examples

Kotlin
import java.util.UUID

val id: String = UUID.randomUUID().toString()   // v4
// "8f2c7b41-0d3e-4a55-b6c1-8e7d9f0a1b2c"

// Keep the UUID object in the model; render to string at the edges
data class Order(val id: UUID = UUID.randomUUID(), val total: Long)
Multiplatform
// commonMain
expect fun randomUuid(): String

// androidMain / jvmMain
actual fun randomUuid(): String = java.util.UUID.randomUUID().toString()

// nativeMain (Kotlin/Native has no java.util)
actual fun randomUuid(): String = platform.Foundation.NSUUID().UUIDString

Frequently Asked Questions

Does Kotlin have its own UUID type?
No. On the JVM and Android you use java.util.UUID; for shared multiplatform code you wrap it behind an expect/actual function.
How do I generate a UUID v7 in Kotlin?
The JDK does not include it. Use the uuid-creator library (UuidCreator.getTimeOrderedEpoch()), or generate the value in the database.
Is UUID.randomUUID() safe on Android?
Yes — it is backed by the platform's secure random generator and is the standard choice for Room or SQLDelight primary keys.

Related tools