Here you can find the source of shuffle(ArrayList
public static <T> ArrayList<T> shuffle(ArrayList<T> population, int sample)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.Collections; public class Main { public static <T> ArrayList<T> shuffle(ArrayList<T> population, int sample) { ArrayList<T> newList = new ArrayList<T>(); ArrayList<T> ret = new ArrayList<T>(); newList.addAll(population);/*from w w w . j a va2 s. c om*/ Collections.shuffle(newList); ret.addAll(newList); for (int i = sample; i < ret.size(); i++) { ret.remove(i); i--; } newList.clear(); return ret; } }