Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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;

   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote