Shuffle elements of ArrayList in Java
Description
The following code shows how to shuffle elements of ArrayList.
Example
/*from w w w . j a v a2s . co m*/
import java.util.ArrayList;
import java.util.Collections;
public class Main {
public static void main(String[] args) {
ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add("A");
arrayList.add("B");
arrayList.add("C");
arrayList.add("D");
arrayList.add("java2s.com");
System.out.println(arrayList);
Collections.shuffle(arrayList);
System.out.println(arrayList);
}
}
The code above generates the following result.