Short UUID conversion and generation library for Java.
- Can make a UUID shorter in string format (down to 22 characters)
Maven
<dependency>
<groupId>co.nlighten</groupId>
<artifactId>short-uuid</artifactId>
<version>0.1.1</version>
</dependency>
Gradle
implementation 'co.nlighten:short-uuid:0.1.1'
import co.nlighten.shortuuid.ShortUuid;
public class Main {
public static void main(String[] args) {
String a = ShortUuid.random(false /* Use Base36 */);
System.out.println(a);
// e.g. "bazl2kp9io74mfdaid40j6xia"
String b = ShortUuid.random(true /* Use Base62 */);
System.out.println(b);
// e.g. "2RGPvdeVim1yS4rHlLpN9f"
// You can also convert a UUID to Base64 (URL)
String c = UuidConverter.toBase64(UUID.randomUUID());
System.out.println(c);
// Shorten an existing UUID
String d = UuidConverter.toShortUuid(UUID.randomUUID(), true /* Use Base62 */);
System.out.println(d);
}
}
See tests for more examples.