You can use RandomStringUtils

import org.apache.commons.lang.RandomStringUtils;
public class RandomStringUtilsTrial {
  public static void main(String[] args) {
    System.out.print("8 char string  >>>");
    System.out.println(RandomStringUtils.random(8, true, true));

  }
}
Answer from bilash.saha on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java string › java – generate random string
Java - Generate Random String | Baeldung
May 11, 2024 - Generate Bounded and Unbounded Random Strings using plain Java and the Apache Commons Lang library.
🌐
Medium
medium.com › @ganeshbn › how-to-generate-a-unique-string-in-java-without-third-party-libraries-a0b9691b2b93
How to Generate a Unique String in Java Without Third-Party Libraries | by GN | Medium
January 19, 2025 - In Java, there are several built-in approaches to generate unique strings without relying on any third-party libraries. In this article…
🌐
GitHub
github.com › aventrix › jnanoid
GitHub - aventrix/jnanoid: A unique string ID generator for Java. · GitHub
It uses a url-friendly alphabet (A-Za-z0-9_-), a secure random number generator, and generates a unique ID with 21 characters. String id = NanoIdUtils.randomNanoId(); // "ku-qLNv1wDmIS5_EcT3j7"
Starred by 516 users
Forked by 58 users
Languages   Java
🌐
CodeJava
codejava.net › coding › generate-random-strings-examples
Generate Random Strings in Java Examples
January 13, 2023 - You can use the java.util.UUID class to generate random strings that are kind of Universally Unique Identifier (UUID).
🌐
Mkyong
mkyong.com › home › java › java – how to generate a random string
Java - How to generate a random String - Mkyong.com
May 4, 2019 - Generate a random String of 32 alphanumeric characters (hexadecimal) and 4 hyphens, read this UUID format ... package com.mkyong; import java.util.UUID; public class UUIDExample { public static void main(String[] args) { for (int i = 0; i < 10; i++) { System.out.println(generateRandomStringByUUIDNoDash()); } for (int i = 0; i < 10; i++) { System.out.println(generateRandomStringByUUIDNoDash()); } } public static String generateRandomStringByUUID() { return UUID.randomUUID().toString(); } public static String generateRandomStringByUUIDNoDash() { return UUID.randomUUID().toString().replace("-", ""); } }
🌐
Medium
medium.com › beingcoders › ways-to-generate-random-string-in-java-6d3b1d964c02
Ways to Create a Random String in Java: Ultimate Guide with Scenarios | BeingCoders
March 16, 2025 - Explore various methods to generate random strings in Java, from basic to advanced techniques, with real-world examples for different…
🌐
Javacodepoint
javacodepoint.com › generate-random-string-in-java
Java Random String | Generate random Strings - Javacodepoint
August 11, 2023 - Write a Java program to find the common elements in two given ArrayLists. ArrayList partition into two separate lists of odd/even numbers. Write a program that extracts a sublist from an ArrayList, given a start and end index. Merge two sorted ArrayLists into a single sorted ArrayList. Find unique string in ArrayList with its frequency
🌐
Programiz
programiz.com › java-programming › examples › generate-random-string
Java Program to Create random strings
Using the random index number, we have generated the random character from the string alphabet. We then used the StringBuilder class to append all the characters together. If we want to change the random string into lower case, we can use the toLowerCase() method of the String.
Find elsewhere
🌐
w3resource
w3resource.com › java-exercises › string › java-string-exercise-18.php
Java - Create a unique identifier of a given string
September 30, 2024 - Java exercises and solution: Write a Java program to create a distinct identifier for a given string.
🌐
Medium
medium.com › @mounikakurapati17 › how-to-generate-unique-number-in-java-ab3acfa82973
How To Generate Unique Number in Java | by Mounika | Medium
December 5, 2022 - To produce a positive unique long value (with extremely low chances of repetition) in Java, using the well-known UUID library, which is also widely used for generating unique strings, a UUID unique long number of the desired length can be obtained as below.
🌐
Coderanch
coderanch.com › t › 565034 › java › Create-Unique-Character-String
How to Create a Unique 16 Character String (Java in General forum at Coderanch)
If it must be unique (that is, even the astronomically small chance of duplicates is unacceptable), and it can't be guessable, then your only real options are: 1) Randomly generate 16 characters, and then compare against a list of already generated IDs, and if it's a duplicate, try again.
🌐
Javapractices
javapractices.com › topic › TopicAction.do
Java Practices->Generating unique IDs
A MessageDigest takes any input, and produces a String which: ... does not uniquely identify the input; however, similar input will produce dissimilar message digests MessageDigest is often used as a checksum, for verifying that data has not been altered since its creation. ... import java.security.SecureRandom; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public final class GenerateId { public static void main (String...
🌐
Liberian Geek
liberiangeek.net › home › how-to/tips › how to generate a random string in java?
How to Generate a Random String in Java? | Liberian Geek
December 19, 2023 - The output confirms that a unique alphabetic random String has been generated after each execution cycle: The custom regular expression can be used with the “Random” class to generate a random String of specific characters. The regular expression method gives more freedom to choose the type of characters users want to enter in their random String: import java.util.Random; import java.nio.charset.Charset; class javabeat { static String randomizer(int strSize) { byte[] tempArray = new byte[255]; new Random().nextBytes(tempArray); String entireRanStr = new String(tempArray, Charset.forName("U
🌐
GeeksforGeeks
geeksforgeeks.org › java › generate-random-string-of-given-size-in-java
Generate random String of given size in Java - GeeksforGeeks
July 11, 2025 - Method 1: Using Math.random() Here the function getAlphaNumericString(n) generates a random number of length a string. This number is an index of a Character and this Character is appended in temporary local variable sb.
🌐
GitHub
gist.github.com › icella › d4011b6808fc549c538c0310528d9e94
Java – Ways to Generate Unique Ids in Java
Java – Ways to Generate Unique Ids in Java · Raw · CurrentTimeId.java · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
🌐
Xperti
xperti.io › home › generate random string in java
Easiest Ways To Generate A Random String In Java
May 9, 2022 - In this article, we will be discussing some easiest approaches using different classes, methods and Java libraries to generate a random string in Java.
🌐
Coderanch
coderanch.com › t › 448702 › java › Creating-Unique-ID-String
Creating a Unique ID from a String. (Java in General forum at Coderanch)
In Java, how can a create a Unique ID from a particular string? I have gone through the UUID class but could not find anything, also googled this but to find nothing. Can any one please Help me on this? ... Try permutation and combination of a string element appended with some Randomized generated string/number.