import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Shuffler {
public static void main(String[] args) {
ListargList = Arrays.asList(args);
Collections.shuffle(argList);
for (String arg : argList)
{
System.out.format("%s ", arg);
}
System.out.println();
}
}
Sep 30, 2009
[Java] Shuffle the contents of a Collection
I was in a situation where i need to shuffle the objects stored inside a collection. Agenda is to generate random questions. Every question is represented as a POJO & stored in a List. Now this does it all.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment