Prefer LinkedHashMaps over HashMaps, really?

53 views
Skip to first unread message

Lam

unread,
Apr 11, 2011, 9:28:40 AM4/11/11
to javapractices-dot-com-discuss
While javapractices.com correctly promotes the use of higher
interfaces, it's weird it says "for business requirements, it is
better to use LinkedHashMaps over HashMaps".

I choose HashMap over LinkedHashMaps unless there's a need for a
predictable iteration order - if the decision is made early on using
LinkedHashMaps, then code that makes use of the collection will use
clever tricks that rely on this behaviour without merit, creating
undocumented coupling, one of the worst kinds of bugs.

i.e. I choose HashSets and HashMap as default over their "Linked"
counterparts precisely because the iteration order is undefined - it's
what maps are for - lookups. If they're iterated, there must be a
real use case otherwise it's wrong.
Reply all
Reply to author
Forward
0 new messages