So I have this method, it not complete because cannot get it work with the set that I have. The set that have has {0,1,2,7,8,9,10}. I tried with an if/else, but it gave me nullpointer exception error. Should I put HashSet objects into an array and then compare the objects? Please provide any insight.
This is customer intersection method, where I have been provided HashSet.java file which contains, the these following methods. 1 - add method 2 - contains method 3 - remove method
public HashSet Intersect(HashSet s1)// only 1 & 2 should be printed
{
HashSet intersect = new HashSet(buckets.length);
Iterator iter = this.iterator();
while(iter.hasNext())
{
intersect.add(iter.next());
}
Iterator iter1 = s1.iterator();
while(intersect.contains(iter1.next()))
{
intersect.remove(iter.next());
}
return intersect;
}