Here you can find the source of shuffle(List
Parameter | Description |
---|---|
list | a parameter |
public static <T> List<T> shuffle(List<T> list)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; import java.util.Random; public class Main { /**/*from w w w . ja v a2 s. c o m*/ * Method to shuffle the list * * @param list * @return {@link List<T>} */ public static <T> List<T> shuffle(List<T> list) { if (list != null && list.size() > 0) { List<T> updatedList = new ArrayList<>(); final int[] ints = new Random().ints(0, list.size()).distinct().limit(list.size()).toArray(); for (int i = 0; i < ints.length; i++) { updatedList.add(list.get(i)); } return updatedList; } return null; } }