Java disconnects ArrayList to generate a random ArrayList, javaarraylist
Write one by yourself. Sometimes it is necessary.
public static <V> boolean isEmpty(ArrayList<V> sourceList) { return (sourceList == null || sourceList.size() == 0); }
/*** Disrupt ArrayList ***/public static <V> ArrayList <V> randomList (ArrayList <V> sourceList) {if (isEmpty (sourceList) {return sourceList ;} arrayList <V> randomList = new ArrayList <V> (sourceList. size (); do {int randomIndex = Math. abs (new Random (). nextInt (sourceList. size (); randomList. add (sourceList. remove (randomIndex);} while (sourceList. size ()> 0); return randomList ;}
[Java] helps to randomly disrupt the order of an array element,
Dizzy. Don't bother.
Convert to list first (why do I use List at the beginning ?)
Example:
String [] arr = new String [] {"1", "2 "};
List list = Arrays. asList (arr );
Directly calling shuffle means random sorting.
Example: Collections. shuffle (list );
Direct output is the result you want.
Java cannot disrupt objects in the arraylist.
As long as a number is selected and inserted at the end, there will be no Bound problem.