Preface
When doing the test paper, you need to mess up the words in a sentence, characters in a word, and answers in multiple-choice questions to create a random sequence. Below I will abstract them into a tool category to facilitate everyone to reuse them in the future.
Sample code
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;} Summarize
The above is all the content of Java disrupting ArrayList to generate a random sequence list, hoping to facilitate everyone's future use of Java. If you have any questions, please leave a message to communicate.