This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hello, I am putting data into a HashMap, and as I put it in, the key's are already in the sort order that I want them to be. However, I understand that if I use map.keySet() I may not retrieve my keys in the same order that I put them into the map. Do you think it is too bulky of a solution to also store the key's into an array at the same time, and then get the array items in order ( zero to arraySize) to use as keys into the hashmap? Or I could put the keys into an ArrayList and retrieve an ieterator of keys in order that way. Any advice appreciated, Thanks.
If using 1.4 you can use LinkedHashMap. This will do exactly what you want. If not, storing the keys in insertion order in a List is not pareticularly wasteful as you are aonly storing a reference to the objects not the objects themselves.
Joined: May 17, 2001
Don, Thanks so much! That is exactly what I needed, but I wasn't aware that there was such an object as LinkedHashMap. I just looked it up and read more about it on the Sun website. This is very helpful to me, thank you very much, Kim
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: retrieving Hashmap keys in order of entry