- package lu.Connection;
- import java.util.HashSet;
- import java.util.Iterator;
- import java.util.Random;
- public class TestSets {
- /**
- * @param args
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Random r=new Random();
- HashSet hs=new HashSet();
-
-
- while(true){
-
- int x=r.nextInt(10);
- System.out.println(x);
- hs.add(" "+x);
-
-
-
-
- if(hs.size()==10){
-
- System.out.println(hs);
-
- break;
- }
-
- }
-
- }
- }
复制代码 打印出来的结果是 [ 9, 8, 1, 0, 3, 2, 5, 4, 7, 6] |