Note: The list file to be written in the same level as the package name under the directory, the record src right click, point new File, copy the list to this file, the program can be based on a number of policies to access the contents of the list
ArrayList is a list, the data is ordered, can have duplicate elements HashSet is set (set), the data is not order, no duplicate elements, the element search speed
Package random Group; import Java.util.arraylist;import java.util.hashset;import java.util.list;import Java.util.Scanner; Import Java.util.set;public class Test {public static void main (string[] args) {list<string> zu=new arraylist<st Ring> (); Scanner sc = new Scanner (Test.class.getClassLoader (). getResourceAsStream ("Table.txt")); while (Sc.hasnextline ()) { String Eachone = Sc.nextline (), if (Eachone!=null && Eachone.trim (). Length () >0) {zu.add (Eachone);// Add to//system.out.print (eachone+ "\ T") in the list collection;}} List order can be repeated//set disorder can not be repeated (this topic recommended to use this, because once your table has a lot of people with the same name it can give you to ignore the duplicate name, but it is the same name of the person also said) set<string> S1 = new Hashset<string> ();//list<string> s1=new arraylist<string> (); int Count=0;//while (TRUE) {if ( Zu.size () ==0) {break;} int index= (int) (Math.random () *zu.size ()); String N=zu.get (Index), if (S1.add (n))//adds the corresponding string (name) to the Set object {System.out.print (n+ "\ T"), Zu.remove (n);//count++;if ( count%7==0)//Control line SYSTEM.OUT.PRINTLN ();}}}
Java programming: Give you a list of classes, randomly divided into 6 groups of problem solving methods