File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes order of  Map Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "order of  Map" Watch "order of  Map" New topic
Author

order of Map

thippareddy mallikarjuna reddy
Greenhorn

Joined: Mar 08, 2006
Posts: 19
Hi pals

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..

...Thanks advance

Thanks
Malliakrjuna
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39396
    
  28
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
Greenhorn

Joined: Mar 08, 2006
Posts: 19
Hi CampBell,

Thanks reply.

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

Thanks
Mallikarjuna
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
LinkedHashMap
thippareddy mallikarjuna reddy
Greenhorn

Joined: Mar 08, 2006
Posts: 19
Hi Jeff Albertson,

Thank you.

cheers
Mallikarjuna
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: order of Map