logo CodeStepByStep logo

mapMystery2

Language/Type: Java Map Set collections

Consider the following method. For each map shown, indicate what values would be stored in the set returned if that map were passed.

public static Set<String> mystery(Map<String, String> data) {
    Set<String> result = new TreeSet<String>();
    for (String s : data.keySet()) {
        result.add(data.get(s));
    }
    return result;
}
{baz=c, mumble=d, foo=a, bar=b}
{f=z, d=x, e=y, b=y, c=z, a=x}
{f=2, g=10, d=20, e=1, b=10, c=2, a=1, h=20}

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.