aspose file tools*
The moose likes Beginning Java and the fly likes Map Family 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 » Beginning Java
Bookmark "Map Family" Watch "Map Family" New topic
Author

Map Family

ajaysharma fbd
Greenhorn

Joined: Aug 06, 2012
Posts: 2
why we don't get order in HashMap.
I know it uses the hashcode but what differnce did it make to the order.
Here By order I mean elements that are added first to the HashMap should be added first I am not talking about sorting.
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4748
    
    7

The implementation is based on a hash function, which is favorable for speed. Sorting/ordering is a different concern that limits the ability to make things work fast. HashMap favors speed. If you need to preserve order, use a SortedMap implementation.


Junilu - [How to Ask Questions] [How to Answer Questions]
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

EnumMap and LinkedHashMap are also ordered. SortedMap also keeps elements sorted though.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Map Family