Getting the key values from Map

HiI need to sort the values in a map based on the key values and put it in a List.Is there any way to get the key values from the Map? Something like getAll( key values )Thanks in advance
[215 byte] By [New_Kida] at [2007-11-26 20:42:49]
# 1
keySet() gives you the keys.values() gives you the values.entrySet() gives you key/value pairs.It's all in the docs.
jverda at 2007-7-10 2:02:45 > top of Java-index,Java Essentials,Java Programming...
# 2

java.util.Map.keySet will give you a java.util.Set holding the keys of the Map.

With that, you can create a java.util.List, passing it the set in the constructor. Then you can sort the list.

Then with the sorted list you can get the values.

Alternatively, you could use Map.entrySet() to get a set of the key/value pairs (instances of Map.Entry) in the map, create a List using those pairs, and then sort the list using a java.util.Comparator that knows how to deal with Map.Entry objects, sorting them by the keys. Then you could iterate through the sorted list and grab the values, or whatever.

paulcwa at 2007-7-10 2:02:45 > top of Java-index,Java Essentials,Java Programming...
# 3
> keySet() gives you the keys.> values() gives you the values.> entrySet() gives you key/value pairs.> > It's all in the docs.Yeah.. Sorry I missed it..Thanks a lot
New_Kida at 2007-7-10 2:02:45 > top of Java-index,Java Essentials,Java Programming...
# 4

> java.util.Map.keySet will give you a java.util.Set

> holding the keys of the Map.

>

> With that, you can create a java.util.List, passing

> it the set in the constructor. Then you can sort the

> list.

>

> Then with the sorted list you can get the values.

>

Great solution man... Exactly wat I did... Thanks in heaps

New_Kida at 2007-7-10 2:02:45 > top of Java-index,Java Essentials,Java Programming...