Sunday, February 12, 2023

How do I generate a random number in Java?

 You can use the java.util.Random class to generate random numbers in Java. Here's an example of how to generate a random integer between 1 and 100:


Random rand = new Random(); int randomNum = rand.nextInt(100) + 1;

No comments:

Post a Comment

Concurrent Hashmap in java

  A ConcurrentHashMap is a thread-safe implementation of the Map interface in Java. Unlike a HashMap , which is not thread-safe and can ca...