Java examples for Collection Framework:List
Shuffling the Elements of a List or Array
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; public class Main { public void m() { // Create a list List list = new ArrayList(); // Add elements to list // Shuffle the elements in the list Collections.shuffle(list);//from w w w .java 2 s . c o m // Create an array String[] array = new String[] { "a", "b", "c" }; // Shuffle the elements in the array Collections.shuffle(Arrays.asList(array)); } }