Marty Stepp (on 2016/06/16) Write the output that is printed when the given meth
ID: 3872953 • Letter: M
Question
Marty Stepp (on 2016/06/16) Write the output that is printed when the given method below is passed each of the following maps as its parameter. Recall that format. Your answer should display the right keys and values in the order they are added to the result map. maps print in a key-value public void collectionMystery1 (HashMapkstring, String map) C HashMap result new HashMapO; for (String k map.keySet) String v map.get (k); if (k . char At (8)v,charAt(8)) { result.put (k, v): else ( result.put (v, k) printin(result); a Sou (two deux, five-cinq, onezun, three trois, four quatre) (skate-board, drive-car, program-computer, play-computer) (siske1-ebert, girl-boy, heads-tails, ready-begin, first-last. begin-end) (cotton-shirt, tree-violin, seed-tree, light-tree, rainscotton) SubmitExplanation / Answer
Let me expaling you the method given before giving answer
public static void collectionMystery4(HashMap<String,String> map, ArrayList<String> list)
{
HashMap<String,String>result = new HashMap<String,String>();
for(int i=0;i<list.size();i++)
{
String s = list.get(i);
if(result.containsKey(s)){
result.put(s,result.get(s)+result.get(s));
}else if(map.containsKey(s)){
result.put(map.get(s),s);
}
}
println(result);
}
//result is a hashmap
below will check the key in map (read from list) or not if yes then appending the text to value.
if(result.containsKey(s)){
result.put(s,result.get(s)+result.get(s));
//if key not in result hashmap making key and value same
else if(map.containsKey(s)){
result.put(map.get(s),s);
}
//first map and result will output:
{Schwarz=Keith, Lee=BruceBruce}
//secod output
{meow=catcat, woof=dogdogdogdog, whinny=horse}
please do let me know if you have any concern...
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.