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()));
random item from arraylist
ArrayList<Type> arraylistName = new ArrayList<>();
// add items to arraylist
arraylistName.add(item1);
arraylistName.add(item2);
arraylistName.add(item3);
Random random = new Random();
// random index between 0 and arraylistName.size();
int randomIndex = random.nextInt(arraylistName.size());
System.out.println(arraylistName.get(randomIndex));
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