subject

What is wrong with the given method called intersect that is supposed to take two Maps of strings to integers as parameters and return a new map whose contents are the intersection of the two. The intersection of two maps is defined here as the set of keys and values that exist in both maps. So if some key K maps to value V in both the first and second maps, include it in your result. If K does not exist as a key in both maps, or if K does not map to the same value V in both maps, exclude that pair from your result. For example, consider the following two maps: {J=87, L=62, W=46, A=100, S=80, J=88, K=52, S=95}
{L=62, K=52, W=52, J=88, S=80, B=60, L=83, S=87}
Calling intersect on the preceding maps would return the following new map (the order of the key/value pairs does not matter):

{L=62, S=80, J=88, K=52}

Correct the following code by rewriting the correct answer in your textbox:

public static Map intersect(Map m1,
Map m2){
Set m2Set= new HashSet<>(m2.keySet());// get the keys of map 1
Set m1Set= new HashSet<>(m1.keySet());// get the keys of map 2
m1Set. retainAll(m2Set);
return m1;
}

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 03:50
Q-1 which of the following can exist as cloud-based it resources? a. physical serverb. virtual serverc. software programd. network device
Answers: 1
question
Computers and Technology, 23.06.2019 19:30
Anul 2017 tocmai s-a încheiat, suntem trişti deoarece era număr prim, însă avem şi o veste bună, anul 2018 este produs de două numere prime, 2 şi 1009. dorel, un adevărat colecţionar de numere prime, şi-a pus întrebarea: “câte numere dintr-un interval [a,b] se pot scrie ca produs de două numere prime? “.
Answers: 3
question
Computers and Technology, 24.06.2019 13:30
Consider jasper’s balance sheet. which shows how to calculate jasper’s net worth?
Answers: 1
question
Computers and Technology, 24.06.2019 13:50
What does code do? a creates a text box that says "solid black" b creates a black border of any width c creates a black border 1 pixel wide
Answers: 1
You know the right answer?
What is wrong with the given method called intersect that is supposed to take two Maps of strings to...
Questions
question
English, 22.02.2021 08:00
question
Social Studies, 22.02.2021 08:00
question
History, 22.02.2021 08:00
question
Social Studies, 22.02.2021 08:00
Questions on the website: 13722363