//这个程序就是弄20个随机数出来存进Set中
public static void main(String[] args) {
Random random = new Random();
HashSet<Integer> set = new HashSet<>();
while(set.size() < 20) {
int i = random.nextInt(20)+1;
set.add(i);
}
System.out.println(set);
}
//[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
//这是输出的结果,刚好是1到20不难理解,可是为什么它会排序呢 |
|