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 17:30
Scientists have changed the model of the atom as they have gathered new evidence. one of the atomic models is shown below. what experimental evidence led to the development of this atomic model from the one before it? a few of the positive particles aimed at a gold foil seemed to bounce back. the colors of light emitted from heated atoms had very specific energies. experiments with water vapor showed that elements combine in specific proportions. cathode rays were bent in the same way whenever a magnet was brought near them.
Answers: 2
question
Computers and Technology, 24.06.2019 10:30
Which of the following types of software is most applicable to the promotion of new products through advertising? a.databases b. spreadsheets c. web design programs d. word processing tools
Answers: 2
question
Computers and Technology, 24.06.2019 18:20
The following if statement contains a logic error, not a syntax error. rewrite it so that it is correct. assume the variable age already exists and holds a valid number. if (age == 18 & & age == 19) {
Answers: 1
question
Computers and Technology, 24.06.2019 19:50
Which is a characteristic of free and open-source software licenses? a. the source code is unavailable to everyone b. the source code is available only to the government c. the source code is available to all users d. the source code is constantly modified
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
Mathematics, 05.10.2019 20:40
question
German, 05.10.2019 20:40
question
Mathematics, 05.10.2019 20:50
question
Social Studies, 05.10.2019 20:50
question
History, 05.10.2019 20:50