I wrote class that represent a Set. in the Set i have a field "elements" of ArrayList. all the methods in the class are generics.
first method i wrote is a method that get another Set as argument and returns new Set that hold the union between this.Set to the argument. here is the method:
public Set<E> union(Set<E> s){
Set<E> toReturn = new Set<>();
for(E toAdd : this.elements) {
toReturn.addToSet(toAdd);
}
for(E toAdd : s.elements)
toReturn.addToSet(toAdd);
return toReturn;
}
Now i want to write another method that get as argument ArrayList> and returns new Set that represent the union between this.Set to all the Sets inside the argument ArrayList. but i can't get access to the Sets inside the ArrayList. here is my code:
public Set<E> union(ArrayList<Set<E>> s) {
Set<E> toReturn = new Set<>();
for(E el : s) {
toReturn.addToSet(s.union(el));
}
return toReturn;
}
The compiler tell me "The method union(E) is undefined for the type ArrayList>.
I'll be happy for some help. Thanks
java.util.ArrayListandjava.util.Setwith your code ?Set? You should never use a build-in nameSetshould be its name.