Question
If I have the method: public static Map pairing(List stringList) { Map map = new HashMap (); for (String str: stringList){ Character key = str.charAt(
If I have the method:
public static Mappairing(List stringList) { Map map = new HashMap<>(); for(String str: stringList){ Character key = str.charAt(0); if (!map.containsKey(key)){ map.put(key, str.charAt(str.length()-1)); } } return map; }
and the following test cases with their corresponding expected result:
Note: In the following expected results {b=g, c=e} means thereare 2 entries in the resulted map: where first entry has 'b' as the key and 'g' as the value, second entry has 'c' as the key and 'e' as the value.
1.pairing(["code", "bug"])expected result:{b=g, c=e}
2.pairing(["man", "moon", "main"])expected result:{m=n}
3.pairing(["man", "moon", "good", "night"])expected result:{g=d, m=n, n=t}
4.pairing([])expected result:{} . The output is an empty Map.
5.pairing(["are", "codes", "and", "cods"])expected result:{a=d, c=s}
6.pairing(["a", "b"])expected result:{a=a, b=b}
Questions:
a)Which one of the above test cases that will not give you the expected result?
b) If you've been asked to resolve this glitch (bug), what you have to change in method code. Write down your code of the method to fix this glitch (bug).
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