3

So what this program is supposed to do is the user inputs a name into a text box and then presses a button to add it into an array which is displayed onto a text area. The thing is that I can't figure out how to take away a name from the arraylist randomly. I am a noob programmer.

Here is what I have so far.

 Random r = new Random();
 ArrayList <String> names = new ArrayList<String>();

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

    names.add(txtAdd.getText());
    txtDisplay.setText("" + names);
 }      

1 Answer 1

5

names.remove(r.nextInt(names.size()));

Sign up to request clarification or add additional context in comments.

2 Comments

Also, how would I change the way the text area looks? like into a list format rather than in brackets? Thank you btw
Arrays.toString(names); I think.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.