import java.util.*;
public class SetKeyWord {
public static void main(String[] args) {
Set s = new HashSet();
s.add("hello");
s.add("world");
s.add("hello");
s.add("hello1");
System.out.println(s);
Set s1 = new HashSet();
Set s2 = new HashSet();
s1.add("a");
s1.add("b");
s1.add("c");
s2.add("a");
s2.add("d");
s2.add("f");
Set sn = new HashSet(s1);
sn.retainAll(s2); // 求交集
Set su = new HashSet(s1);
su.addAll(s2);
System.out.println(sn);
System.out.println(su);
}
}
java Set 用法
最新推荐文章于 2022-06-17 21:46:53 发布