Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 (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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started