package com.heima.set;
import java.util.HashSet;
import java.util.Random;
public class Demo2_HashSet {
/**
* @param args
*/
public static void main(String[] args) {
//创建随机数对象
Random r = new Random();
//创建HashSet对象
HashSet<Integer> hs = new HashSet<>();
while (hs.size() < 10) {
hs.add(r.nextInt(20) + 1);
}
for (Integer integer : hs) {
System.out.println(integer);
}
}
}
|
|