Android java how to have it select a random string from a predetermined list of strings


Ask by : Cole Selensky November 03, 2012 22:05

Answer by : Eng.FouadNovember 03, 2012 22:05

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);
View original answer