guliing guliing - 9 months ago 42
Java Question

Randomize from a made list

ArrayList<String> listArray = new ArrayList<String>();

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

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

It said i couldn't use


you can do like this

Random ran = new Random();
String random = (String) list.get(ran.nextInt(list.size()));
System.out.println("random :"+rdom);