File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Linked Hash Map Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Linked Hash Map" Watch "Linked Hash Map" New topic

Linked Hash Map

sreedhar Lackka
Ranch Hand

Joined: Jul 05, 2008
Posts: 154
Hi All,
Thanks a lot in advance.

We are planning to use cache but we dont have any cache mechanism in the cache actually there should be some thing which provide the key, value and entry iteration that are consistent with an order of entry.
For this we came up with two approaches indexing that list and LisnkedHashMap.
But dont know what are disadvantages and overheads with LinkedhashMap.
Please give me some useful information and suggestions on this.

Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2904

Look at this.

[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Dariusz Kordonski
Ranch Hand

Joined: Jul 11, 2008
Posts: 49
If you need ordered key-value entries, then I think LHM it is simply the most natural choice for you (as far as Java is concerned). There may be some collection implementations that provide better performance, but frankly, I doubt it would be more than a marginal difference. One thing that might be significant in your case is that LHM is not synchronized. However, you may always use Collections#synchronizedMap() to enforce it. I looked in java.util.concurrent package, but haven't found ordered concurrent map implementation.
Rajkamal Pillai
Ranch Hand

Joined: Mar 02, 2005
Posts: 445


A LikedHashTable would be synchronized too right?

Dariusz Kordonski
Ranch Hand

Joined: Jul 11, 2008
Posts: 49
I'm afraid there is no such class in the Java API (at least I never heard of it ). There is java.util.Hashtable and java.util.concurrent.ConcurrentHashMap (which are quite similar, with the latter being a bit faster for some operations), but as far as I know, neither of them supports element ordering, which is one of Sreedhar's requirements.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20276

Well, you can always wrap your LinkedHashMap using java.util.Collections#synchronizedMap

How To Ask Questions How To Answer Questions
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46410
Originally posted by Sagar Rohankar:
Look at this.
Did you actually look at it? All the information you require was there.
I agree. Here's the link:
subject: Linked Hash Map
jQuery in Action, 3rd edition