1.代码:
public static void main(String[] args) {
HashSet set= new HashSet();//字符串集合
for (int i = 0; i < 10; i++) {
HashSet<Character> one= new HashSet<>();//字符集合
for (int j = 0; j < 10; j++) {
//内层遍历除每个的随机10个的字符集合组成一个字符串,
char a=(char)(Math.random()*26+65);//数字对应的ASC表字符
one.add(a);//添加字符到集合
}
System.out.println(one);
ArrayList<Character> list = new ArrayList<>(one);//set转为list! 如果不转换进行遍历呢?那就不能进行打乱了
Collections.shuffle(list);//打乱字符串
String str = "";//得到增强for循环内的值 字符串
for (Object o: one) {
str=str+o;//将o的值赋给str,得到字符的遍历形成字符串
}
set.add(str);//添加并去重
}
// for (Object o : set) {//遍历字符串
// System.out.println(o);
// }
System.out.println(set);
System.out.println("字符串数量:"+set.size());
}
2.结果: