guliing guliing - 1 year ago 64
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

Answer Source

you can do like this

Random ran = new Random();
String random = (String) list.get(ran.nextInt(list.size()));
System.out.println("random :"+rdom);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download