I have a requirement that a Map will be constructed with up to 50~200 entries (it could be more, let's call it not-too-little anyway). The writing is only done once and the reading (using Map.get("keyName")) can go more than 20 per request (it's a webapp).
I'm going for Hashmap currently as it (I suppose) gives me the most optimum performance (note: numerous reads per request). Not being a data-structure guy, can any of you suggest a Map implementation that's best fit for my requirement, say from the java.lang.*, Apache commons, etc. packages?
yc
Unless you are actually having performance problems (and have traced them to this code) I wouldn't worry about it.
And before I tried to replace the Map I'd look at why, exactly, I need to do 4000 lookups (200 entries by 20 reads each) to generate a web page.
But at a bet I'd guess that the time to do those 4000 lookups will turn out to be negligible compared to other parts of the process.
If all of the writes are done before any of the reads then you could use the Collectons.unmodifiableMap method.
If that isn't the case then writing code to do what you want isn't terribly hard (wanders off to find the post that has the basic code in it...)
Hmm... just to be sure that the question is what I am thinking... is the read only aspect the important part or is trying to access the data fast the most important part?
Edit: (based on comment)
Have you checked to see, with a profiler if the code is slow? If not then you should not be worrying about it yet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With