Randomize an Array in Java

2/17/2014 3:06:53 PM

The following will take an ArrayList (in this example a list of strings) that is populated with values and randomly shuffle the values.

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

ArrayList<String> characters = new ArrayList<String>();

//write code to populate array of characters

//shuffle characters
long seed = System.nanoTime();
Collections.shuffle(characters, new Random(seed));