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.
I am using HashMap.iam adding some values in to HashMap. for example. i added 200 results in to HashMap .first 1000 results of HashMap belongs to one part and another 100 results of HashMap belongs to another part.
My problem is :
The Hashmap does not maintain order which i entered into HAshMap. the results are combined. now i have to maintain order....
can you advice me which collection calss will work for this type of probelm..
If you add your values to a HashMap, as you know, you have to specify a key and a value, and the HashMap takes the hashCode of the key to decide where to put the value. So unless you have keys which return different hashCodes from one another, you are going to find the values mixed up together.
I can't offhand think of a Collection type which will separate values like that; have a look in the Collections part of the Java tutorial and see whether that helps. You could subdivide a Collection by index, but that fixes its size and vitiates the benefit of Collection classes altoghether.
Does anybody else know of a collection which can be subdivided like that?
thippareddy mallikarjuna reddy
Joined: Mar 08, 2006
I added values into HAshMAp based on Key.first 100 keys belongs to one part and second 200 keys belongs to another part. now i got output with mixed. so now i need to get order which i entered in to Hashmap