集合类中的set

  • HashSet的使用

1. HashSet存储字符串并遍历

HashSet<String> hs = new HashSet<>();

boolean b1 = hs.add("a");

boolean b2 = hs.add("a");

System.out.println(b1);

System.out.println(b2);

for(String s : hs) {

System.out.println(s);

}

猜你喜欢

转载自blog.csdn.net/weixin_38107457/article/details/120661738