logo CodeStepByStep logo

collectionMystery1

Language/Type: Java collection mystery collections

Write the output that is printed when the given method below is passed each of the following maps as its parameter. Recall that maps print in a key=value format. Your answer should display the right keys and values in the order they are added to the result map.

public static void collectionMystery1(HashMap<String, String> map) {
    HashMap<String, String> result = new HashMap<String, String>();
    for (String k : map.keySet()) {
        String v = map.get(k);
        if (k.charAt(0) <= v.charAt(0)) {
            result.put(k, v);
        } else {
            result.put(v, k);
        }
    }
    System.out.println(result);
}
{two=deux, five=cinq, one=un, three=trois, four=quatre}
{skate=board, drive=car, program=computer, play=computer}
{siskel=ebert, girl=boy, heads=tails, ready=begin, first=last, begin=end}
{cotton=shirt, tree=violin, seed=tree, light=tree, rain=cotton}

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.