Hi frnds.. Hey i just need one small help. Could u please tell me that which collection object i have to use so that while retriving i can get the data in sorted order and just let me know suppose while retriving the data when it gives in sorted data is it dependent on the key of the map. I need the collection object in MAP interface.
If all you want to sort is a set of Strings, you can also use the TreeSet class, which is truly a Collection in the capital "C" sense of the word (note that the TreeMap class does not officially implement the Collection interface, but is a collection in the generic sense).
Here's a TreeMap example; Maps store key-value pairs, so I'm using Strings as keys, Animal objects as values. (Note that we can use ANY type of Object for both the key or the value, but there's more work to do if we use an arbitrary type of object X as the key -- namely, we have to write additional code to define what it means for one instance of X to be less than/equal to/greater than another instance of X.)
Hope this helps!
Joined: Dec 20, 2000
Originally posted by Jacquie Barker: If all you want to sort is a set of Strings, you can also use the TreeSet class ...
Just to clarify: a TreeSet can also sort Objects in general, not just Strings -- see my comments in the TreeMap example.
Joined: Nov 26, 2004
This is in case you wanted to sort the values
use Collections.sort() method to do the sorting
sorry for that part, It should have been Arrays.sort() [ July 15, 2005: Message edited by: Rajagopal Manohar ]