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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Map Family" Watch "Map Family" New topic

Map Family

ajaysharma fbd

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

Joined: Feb 26, 2001
Posts: 4447

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

Joined: Sep 20, 2010
Posts: 3605

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