Java programming: give you a list of classes and divide them into six groups at random.

Source: Internet
Author: User

Java programming: give you a list of classes and divide them into six groups at random.

Note: The target list file should be written in the directory at the same level as the package name, record src, right-click, create a file, and copy the list to this file, the program can access the content of this list according to some policies.

ArrayList is a List and data is ordered. The HashSet element can be a Set. The data has no sequence and no repeated elements. The element search speed is fast.
Random package grouping; import java. util. arrayList; import java. util. hashSet; import java. util. list; import java. util. imports; import java. util. set; public class Test {public static void main (String [] args) {List
 
  
Zu = new ArrayList
  
   
(); Using SC = new using (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 the List set // System. out. print (eachOne + "\ t") ;}// the list can be repeated in an ordered manner. // The set can be unordered and cannot be repeated. (This is recommended for this question, because once many people with the same name are recorded in your table, they can ignore duplicate names for you, but they are people with the same name.) Set
   
    
S1 = new HashSet
    
     
(); // List
     
      
S1 = new ArrayList
      
        (); 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) // Add the corresponding string (name) to the set object {System. out. print (n + "\ t"); zu. remove (n); // count ++; if (count % 7 = 0) // controls the line feed System. out. println ();}}}}
      
     
    
   
  
 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.