• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

order of Map

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
LinkedHashMap
 
thippareddy mallikarjuna reddy
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jeff Albertson,

Thank you.

cheers
Mallikarjuna
 
reply
    Bookmark Topic Watch Topic
  • New Topic