Shuffling the Elements of a List or Array

Use Collections.shuffle() to randomly reorder the elements in a list.
// Create a list List list = new ArrayList(); // Add elements to list // Shuffle the elements in the list Collections.shuffle(list); // Create an array String[] array = new String[]{"a", "b", "c"}; // Shuffle the elements in the array Collections.shuffle(Arrays.asList(array));

Comments

11 Mar 2010 - 3:12am by oviya (not verified)

very supportive

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.