select a random element from a list java
Random randomizer = new Random();
String random = list.get(randomizer.nextInt(list.size()));
select a random element from a list java
Random randomizer = new Random();
String random = list.get(randomizer.nextInt(list.size()));
how to select a random element from an array in java
import java.util.Random;
public class RandomStringFromArray
{
public static void main(String[] args)
{
String[] arr={"1", "2", "3", "4", "5"};
Random r=new Random();
int randomNumber=r.nextInt(arr.length);
System.out.println(arr[randomNumber]);
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us