Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2006

Tip: Looking for answers? Try searching our database.

Collections performance

Thread view: 
Chris - 31 Aug 2006 23:55 GMT
Does anyone know of a good benchmark of HashMap, TreeMap, and maybe some
other alternatives like Trove?

I need to add items to a map, and then get them out in sorted order, and
I'm wondering if it it's faster to use a HashMap, copy to an array, and
then sort, or just use a TreeMap.
Steve W. Jackson - 01 Sep 2006 17:23 GMT
> Does anyone know of a good benchmark of HashMap, TreeMap, and maybe some
> other alternatives like Trove?
>
> I need to add items to a map, and then get them out in sorted order, and
> I'm wondering if it it's faster to use a HashMap, copy to an array, and
> then sort, or just use a TreeMap.

I don't know of any benchmarks and never heard of Trove.  But I can tell
you that, having made extensive use of Java's Collections, they perform
quite well.  (And see the Javadocs for some performance information.)

As to whether to use a HashMap or TreeMap, I'd say it would depend on
just how often you need the entire set of data in the sorted order of
your keys.  If it's seldom, and the data set isn't exceedingly large, I
suppose it *could* make sense to get all the keys and iterate over them
in sorted order.  If you need to iterate over the entire set frequently,
then the TreeMap is likely to be better.  Without more information, it's
even possible that neither of these would be your ideal choice...it all
depends on what you need to accomplish.

= Steve =
Signature

Steve W. Jackson
Montgomery, Alabama



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.