dimanche 18 septembre 2016

Randomize from a made list

ArrayList listArray = new ArrayList();

private void AddToListActionPerformed(java.awt.event.ActionEvent evt) {                                         
    String addTo = txtAdd.getText();
    listArray.add(addTo);
}                                        

private void randomPickerActionPerformed(java.awt.event.ActionEvent evt) {                                         

} 

In the button randomPicker, I want to print out one of the random strings I added in my array. Can you guys help me out with what I should write inside that button?

I tried: String random = (listArray[new Random().nextInt(listArray.length)]); System.out.println(random);

It said i couldnt use nextInt...




Aucun commentaire:

Enregistrer un commentaire