File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Performance
Bookmark "which is more efficient?" Watch "which is more efficient?" New topic

which is more efficient?

ajm jsk

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

Joined: Oct 02, 2003
Posts: 11952

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:
subject: which is more efficient?
It's not a secret anymore!