2021-05-12

1.创建set文件夹
建Java HashSetDemo

public class HashSetDemo {
    public static void main(String[] args) {
        HashSet set = new HashSet<>(); //  <> 钻石语法
        set.add("111");
        set.add("222");
        set.add("333");
        set.add("小明");
        set.add("小华");
        set.add("aaa");
        set.add("bbb");
        set.add("xxx");
        System.out.println(set);
        set.remove("xxx"); // 根据内容移除
        System.out.println(set);
        int size = set.size();
        boolean empty = set.isEmpty();
        System.out.println(size);
        System.out.println(empty);
        set.clear();  // 清除
        System.out.println(set);
    }
}

2.建Java TreeSetDemo

public class TreeSetDemo {
    public static void main(String[] args) {
        TreeSet set = new TreeSet<>();
        set.add("111");
        set.add("222");
        set.add("地理");
        set.add("历史");
        set.add("asdd");
        set.add("ASDD");
        System.out.println(set);
        //set.clear();
        System.out.println(set.pollFirst());
        System.out.println(set);

    }
}

你可能感兴趣的:(2021-05-12)