Demo05_Set.java 468 B

123456789101112131415161718192021222324
  1. package J20250722;
  2. import java.util.HashSet;
  3. import java.util.Set;
  4. /**
  5. * @author WanJl
  6. * @version 1.0
  7. * @title Demo05_Set
  8. * @description
  9. * @create 2025/7/22
  10. */
  11. public class Demo05_Set {
  12. public static void main(String[] args) {
  13. Set<String> set=new HashSet<>();
  14. set.add("Hello");
  15. set.add("zhangsan");
  16. set.add("wangwu");
  17. //遍历 foreach
  18. for(String s: set){
  19. System.out.println(s);
  20. }
  21. }
  22. }