Shuffle elements of an array in Java
Description
The following code shows how to shuffle elements of an array.
Example
/* w w w . j av a2s . com*/
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Main {
public static void main(String[] args) {
String[] alphabets = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "Java2s.com" };
List<String> list = Arrays.asList(alphabets);
System.out.print(list);
Collections.shuffle(list);
System.out.print(list);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »