Question: 3. Consider the following incomplete intersection method. public static Set intersection (Set 31, Set 32) // precondition: 31 and 32 are both non-empty and store

 3. Consider the following incomplete intersection method. public static Set intersection

3. Consider the following incomplete intersection method. public static Set intersection (Set 31, Set 32) // precondition: 31 and 32 are both non-empty and store Integer objects. // postcondition: intersection returns the intersection of sets 31 and 32. { /* missing code +/ } Which of the following three implementations of /* missing code */ will make the method work as intended? Implementation 1 Set temp = new HashSet(); Iterator iter = 31. iterator(); while (iter. hasNext() { Integer number = (Integer) iter.next(); if (32.contains (number)) temp.add(number); } return temp; Implementation 2 Set temp = new HashSet(); Iterator iteri = 31.iterator(); Iterator iter2 = 32. iterator(); while (iter.hasNext()) { Object numberl = iteri.next(); temp.add(number1); } while (iter2.hastNext()) { Object number2 = iter2.next(); temp.add(number); } return temp; Implementation 3 Set temp = new HashSet(); Iterator iter = 31.iterator(); while (iter.hasNext()) { Integer number = (Integer) iter.next(); if (!32.contains (number)) temp.add(number); } return temp; (A) Implementation 1 only (B) Implementation 2 only (C) Implementation 3 only (D) Implementation 1 & 2 only (E) Implementation 2 & 3 only

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!