I need a help with writing two methods described below: public boolean removeAll
ID: 3724414 • Letter: I
Question
I need a help with writing two methods described below:
public boolean removeAll(Set s) – removes all elements of s contained in the current set. Return true if at least one element is removed. Otherwise, return false.
Example: If the current Set = {1, 2, 8} and s = {2, 3} the the current Set = {1, 8}
public boolean retainAll(Set s) – removes all elements from the current set that are not contained in S. Return true if at least one element is removed. Otherwise, return false.
Example: If the current Set = {1, 2, 3, 8} and s = {2, 3, 5} the the current Set = {2, 3}
It is java programming. eclipse
Explanation / Answer
public boolean removeAll(Set s) {
boolean falg = false;
for(Object i : s) {
if(current.contains(i)){
current.remove(i);
falg = true;
}
}
return falg;
}
########
public boolean retainAll(Set s) {
boolean falg = false;
for(Object i : current) {
if(!s.contains(i)){
current.remove(i);
falg = true;
}
}
return falg;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.