You have a HashMap whose keys need to be retrived in a sorted manner which of the following will be used to achieve this..
1.copy the contents of hashmap into a tree map 2.pass hashmap to Arryas.sort() 3.pass hashmap to collections().sort() 4.Add the kesy of Hashmap to tree set
i guess 1 & 2 options
posted 9 years ago
Option 1 should work: a TreeMap "class guarantees that the map will be in ascending key order". Option 2 won't work because Arrays.sort() is only defined for array types. Option 3 won't work because Collections.sort() is defined only for things that implement a List interface. Option 4 should also work, because the question implies you're only interested in retrieving the keys (and not the values).