java.util.Collections.shuffle() 随机方法


java.util.Collections.shuffle() 随机方法

package com.codingdict;

import java.util.*;

public class CollectionsDemo {
   public static void main(String args[]) {  

      // create Linked List
      LinkedList<Integer> list = new LinkedList<Integer>();

      // populate list
      list.add(52);  
      list.add(27);  
      list.add(14);  
      list.add(-33);

      System.out.println("List before shuffle: "+list);   

      // shuffle the list
      Collections.shuffle(list);  

      System.out.println("List after shuffle: "+list);
   }
}