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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 21:30, mima851
Elements such as fonts colors visual structure graphics and the interface of a web page should complement each other to ensure blank
Answers: 3
image
Computers and Technology, 23.06.2019 18:00, teamroper35
Which finger presses the h key on the keyboard? index finger on the left hand pinky finger on the right hand index finger on the right hand thumb on the left hand
Answers: 1
image
Computers and Technology, 24.06.2019 07:30, isabelgalvarado2838
Jason is working on a microsoft excel worksheet and he wants to create a print preview shortcut. his teacher asks him to access the customization option to create the new shortcut. which two tabs should jason select to place the print preview shortcut on the worksheet toolbar? a. new tab (custom) and new group (custom) b. new file tab (custom) and new tab (custom) c. new custom group and new command d. new custom tab and new command
Answers: 2
image
Computers and Technology, 24.06.2019 12:00, tipbri6380
An npn transistor is correctly biased and turned on if the a. base is negative. b. collector is negative. c. collector is positive with respect to the emitter and negative with respect to the base. d. collector is the most positive lead followed by the base.
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 in other subjects:

Konu
Mathematics, 11.06.2020 20:57