有两个集合,A集合内容为:{1、2、3、4},B集合内容为:{1、2、5、6}

2025-02-28 23:39:35
推荐回答(1个)
回答1:

public class Test2 {
public static HashSet hs1=new HashSet();
public static HashSet hs2=new HashSet();
public static void init()
{
Integer[] A={1,2,3,4};
Integer[] B={1,2,5,6};
for(int i=0;i {
hs1.add(A[i]);
}
for(int i=0;i {
hs2.add(B[i]);
}
}
public static void main(String args[])
{
init();
for(Integer i:hs1)
{
if(hs2.contains(i))
{
hs2.remove(i);
}
else
{
hs2.add(i);
}
}
System.out.println(hs2);
}
}