Welcome Guest | Sign in | Register
Collections - Discussion Page For Q.2573 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Collections > Questions and Answers

Q: 1. HashMap props = new HashMap();
2. props.put("key45", "some value");
3. props.put("key12", "some other value");
4. props.put("key39", "yet another value");
5. Set s = props.keySet();
6. // insert code here
What, inserted at line 6, will sort the keys in the props HashMap?
A. Arrays.sort(s); B. s = new TreeSet(s);
C. Collections.sort(s); D. s = new SortedSet(s);

Answer and Explanation

Answer:s = new TreeSet(s);

Explanation:
If you store HashMap values into TreeSet then values will get sorted automatically,so here we are storing HashMap values into TreeSet. 

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.