Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

I want to generate random strings in an efficient way for alphanumeric characters without dashes or special symbols. I tried UUID.randomUUID().toString(), but it generates the string with dash like this 44e128a5-ac7a-4c9a-be4c-224b6bf81b20. 

Can anyone tell me how to do it?

1 Answer

0 votes
by (19.7k points)

Check the below code:

public static void main(String[] args) {

    final String uuid = UUID.randomUUID().toString().replace("-", "");

    System.out.println("uuid = " + uuid);

}

Interested in Java? Check out this Java Certification by Intellipaat.     

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Feb 11, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
asked Feb 25, 2021 in Java by rahulnayar01123 (6.1k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...