Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Performance and the fly likes which is more efficient? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "which is more efficient?" Watch "which is more efficient?" New topic
Author

which is more efficient?

ajm jsk
Greenhorn

Joined: Apr 07, 2009
Posts: 1
i have two data structures, one is int(key) and another is list of int's (value).
I am just thinking that out of all the data structures that java has, which one will be more efficient here to use as a key value pair?

( treemap, map, hashmap, etc)
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Map is an abstract data type. HashMap, TreeMap, IdentityHashMap etc are implementation of Map.

now question is which is efficient? it is entirely depends on your situation. each implementation has its own tradeoff.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

and Welcome to JavaRanch ajm jsk !
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11497
    
  16

Why does it matter? Odds are the difference in speed will be imperceptible for any application you will write. What you should be focusing on is what makes the most sense - what is easiest to write, what is easiest to understand, and what is easiest to maintain.

Picking a data structure based on some ill-defined efficiency need is guaranteed to cause you more headaches than it is ever going to be worth.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: which is more efficient?