java arraylist choose random code example
Example 1: random item from arraylist
ArrayList<Type> arraylistName = new ArrayList<>();
arraylistName.add(item1);
arraylistName.add(item2);
arraylistName.add(item3);
Random random = new Random();
int randomIndex = random.nextInt(arraylistName.size());
System.out.println(arraylistName.get(randomIndex));
Example 2: get random String from array list
Random r = new Random();
int randomitem = r.nextInt(myList.size());
String randomElement = myList.get(randomitem);