Given the code fragment:public class Foo {public static void main (String [ ] args) {Map<Integer, String> unsortMap = ne

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899559
Joined: Mon Aug 02, 2021 8:13 am

Given the code fragment:public class Foo {public static void main (String [ ] args) {Map<Integer, String> unsortMap = ne

Post by answerhappygod »

Given the code fragment:public class Foo {public static void main (String [ ] args) {Map<Integer, String> unsortMap = new HashMap< > ( );unsortMap.put (10, "z");unsortMap.put (5, "b");unsortMap.put (1, "d");unsortMap.put (7, "e");unsortMap.put (50, "j");Map<Integer, String> treeMap = new TreeMap <Integer, String> (newComparator<Integer> ( ) {@Override public int compare (Integer o1, Integer o2) {return o2.compareTo(o1); } } );treeMap.putAll (unsortMap);for (Map.Entry<Integer, String> entry : treeMap.entrySet () ) {System.out.print (entry.getValue () + " ");}}}What is the result?

A. A compilation error occurs.
B. d b e z j
C. j z e b d
D. z b d e j
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!

This question has been solved and has 1 reply.

You must be registered to view answers and replies in this topic. Registration is free.


Register Login
 
Post Reply