-1

Possible Duplicate:
Random string from string array list

How can I make it where i can press a button and it display one sting (words) at random from a long list of of other strings that i have already set.

Community
  • 1
  • 1
  • 2
    Ehem... do you want to know how to implement a button, how to display a string, or how to choose a random string from a list? – Axel Nov 03 '12 at 22:05

1 Answers1

3
List<String> list = new ArrayList<String>();
list.add(...);
list.add(...);
list.add(...);
Random rand = new Random();
String random = list.get(rand.nextInt(list.size()));

or:

Collections.shuffle(list);
String random = list.get(0);
Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417