on 08-16-2007 8:34 AM
Hi,
Can the keys and values in Hash Map or any other type of map be put in one's desired Order? I want to send the attributes of a node in a particular order to a Generic Print Component and want to get the attributes in same order and print them. When i am using Hash Map or Tree Map the order of key-value pairs is changed accoding to hash code or Alphabetical order of keys respectively.
Regards,
Smriti.
Hi Smriti,
Have you tried java.util.LinkedHashMap? The keys are saved in the order they were introduced to the map. For the rest, it works as a HashMap.
I hope this can help you.
Eneko.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The order cann't be maintained.
HashMap and Hashtable both are not ordered.
Regards,
Ashwani Kr Sharma
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ahswani,
Can you please tell me with the help of an example how to send Attribute Information via arrayList or Vector. I won't be able to sort the Hash map in a particular order on the other side as its being passed to a generic component and order will be different for all the maps being passed.
Thanks and Regards,
Smriti
Hi,
Well i think you generic print component accepts HashMap or HashTable.
If you can control over this, change the implementation so that it accepts ArrayList as input.
Can create a generic class . lets say "KeyValuePair" with field like Object key and Object value.
Create instances of this KeyValuePair to store the key and values. Now put them in ArrayList.
Now in print component if you get this arraylist which is ordered.
Regards,
Ashwani Kr Sharma
For sorting of HashMap:
http://www.theserverside.com/discussions/thread.tss?thread_id=29569
Regards,
Ashwani Kr Sharma
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.