wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 4442
    
    5

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: 3575
    
  14

EnumMap and LinkedHashMap are also ordered. SortedMap also keeps elements sorted though.
 
wood burning stoves
 
subject: Map Family
 
Similar Threads
retrieving values of multiple <input> tag with same name at server side
WA #1.....word association
how to prove that Hashtable is not ordered
For Virgins Only
Style Guide question