What is the output of the following code segment? Map<Integer, String>m = new Tr
ID: 3610428 • Letter: W
Question
What is the output of the following code segment? Map<Integer, String>m = new TreeMap<Integer,String>(); m.put(1,"Amy"); m.put(4,"Ann"); m.put(new Integer(3),"Emy"); m.put(2,"Sue"); m.put(new Integer(8),"Lea"); 19. System.out.println(m.get(1)); 20. System.out.println(m.get(3)); for(int i :m.keySet()) 21. System.out.print(m.get(i) +" "); 22. System.out.println(m.remove(2)); 19.________ 20.________ 21.________ 22.________ What is the output of the following code segment? Map<Integer, String>m = new TreeMap<Integer,String>(); m.put(1,"Amy"); m.put(4,"Ann"); m.put(new Integer(3),"Emy"); m.put(2,"Sue"); m.put(new Integer(8),"Lea"); 19. System.out.println(m.get(1)); 20. System.out.println(m.get(3)); for(int i :m.keySet()) 21. System.out.print(m.get(i) +" "); 22. System.out.println(m.remove(2)); 19.________ 20.________ 21.________ 22.________Explanation / Answer
TreeMap - stores objects in a Map, where any subcollection oriterator obtained will be sorted by the key values
theMap object stores by key; since a TreeMap is used, its iteratorreturns the elements sorted in order by the keys
Map<Integer, String> m = newTreeMap<Integer,String>();
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.