Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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));
Comment

PREVIOUS NEXT
Code Example
Java :: bukkit scheduler delay task 
Java :: javafx dependency 
Java :: string to date android 
Java :: java execution time 
Java :: react-native force rtl on android 
Java :: android studio lower case letters on a button 
Java :: spring boot security maven 
Java :: java int to roman 
Java :: zufallszahlen in java 
Java :: swing disable button 
Java :: bukkit inventory set name 
Java :: check java version linux 
Java :: java remove first character from string 
Java :: spigot how to make an inventory 
Java :: android java increment hashmap value 
Java :: how to reverse order of arraylist 
Java :: print up to 2 decimal in java 
Java :: java math.pi 
Java :: firebase storage dependency 
Java :: padding a string with 0 in java 
Java :: java jpanel message error messages 
Java :: java create date object from yesterday 
Java :: floatingactionbutton image color 
Java :: android parse time 
Java :: Which package contains the Java Collections Framework? Group of answer choices java.net 
Java :: java product 1 to n 
Java :: android java format date time 
Java :: java get size of jframe 
Java :: java loop through string 
Java :: Not supported for DML operations 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =