Today, the team leader gave a binding task, the business needs to be a man and a woman random teacher bound to the examination room.
Test example into the following:
1 Packagecom.test;2 3 Importjava.util.ArrayList;4 Importjava.util.List;5 6 Public classTest {7 8 /**9 * @paramargsTen */ One Public Static voidMain (string[] args) { A //TODO auto-generated Method Stub -list<string> ones =NewArraylist<string>(); -Ones.add ("1 male"); theOnes.add ("2 Male"); -Ones.add ("3 Male"); -Ones.add ("4 Male"); -Ones.add ("5 male"); +Ones.add ("6 Male"); -List<string> twos =NewArraylist<string>(); +Twos.add ("7 Women"); ATwos.add ("8 Women"); atTwos.add ("9 Women"); -Twos.add ("10 Women"); -Twos.add ("11 Women"); -Twos.add ("12 Women"); -List<string> STRs =NewArraylist<string>(); - intA =ones.size (); in for(inti = 0; i < A; i++) { - intIndex1 = (int) (Math.random () *ones.size ()); to intIndex2 = (int) (Math.random () *twos.size ()); +Strs.add ("[" +ones.get (INDEX1) + "," +twos.get (INDEX2) + "]"); - Ones.remove (index1); the Twos.remove (INDEX2); * } $ System.out.println (STRs);Panax Notoginseng } - the}
In fact, the principle is to follow the irregular take out, put into a new list, removed in the Remove.
Two different lists are randomly grouped into a list.