Shuffle a list in Java
Description
The following code shows how to shuffle a list.
Example
// www . j ava 2 s . c o m
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Main
{
public static void main(String[] args)
{
List<Integer> numbers = new ArrayList<Integer>();
for (int i = 1; i <= 49; i++)
numbers.add(i);
Collections.shuffle(numbers);
List<Integer> winningCombination = numbers.subList(0, 6);
Collections.sort(winningCombination);
System.out.println(winningCombination);
}
}
The code above generates the following result.