Java programming: Give you a list of classes, randomly divided into 6 groups of problem solving methods

Source: Internet
Author: User

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

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.