Java examples for java.util:Collection Element
Answer a random element from source Collection
import java.util.*; public class Main{ public static void main(String[] argv){ Collection source = java.util.Arrays.asList("asdf","book2s.com"); System.out.println(pickRandom(source)); }//w w w . ja v a 2 s.c o m /** * Answer a random element from source Creation date: (13.10.2002 17:08:01) * * @return java.lang.Object * @param source * java.util.Collection */ public static Object pickRandom(Collection source) { Object[] S = source.toArray(); return S[MathUtils.random(0, S.length)]; } }