HashMap vs IdentityHashMap

Hello

I'm developing an application where a series of Client objects must be stored in a HashMap, using unique String ID values as keys. Every client has a unique ID, represented in a String key in the HashMap. Now I can't figure out whether I could be able to use IdentityHashMap instead of the regular HashMap. Here's what I found over at jGuru, but I'm not sure about the differences:

"The IdentityHashMap uses == for equality checking instead of equals(). This can be used for both performance reasons, if you know that two different elements will never be equals and for preventing spoofing, where an object tries to imitate another."

All I can come up with that looks like a potential bottleneck, is that I retrieve the Client ID numerics from incoming data over a network connection, I then use those Strings to get() the Client object in the HashMap.

While on the subject of HashMap's, I also have an Iterator looping through the HashMap at times, removing clients from it. However, due to it being fail-safe I must first move the ID's of clients-to-be-removed to a seperate collection, and when I'm finished I have to loop through that collection, removing every element in it from the client HashMap. Any ideas on how I could remove the clients immediately as I loop through the HashMap? Performance is trivial, as Client's are stored in a HashMap per Server (up to 20 000 clients per server theoretically).

Thank you

[1479 byte] By [trons_be] at [2007-9-27 14:13:39]
# 1

I havent used IdentityHashMap myself but from your description, if you retrieve the string from the network and use that to retrieve the key, you cant rely on the IdentityHashMap to work. If it checks the key equality with == instead of equals() method, they would have to point to the same object. Considering how strings are impleted this might happen but you cant count on it.

what do you mean by need for fail-safe in q2? how does the 2-step process make it fail-safe and what does it make it fail-safe from?

teka at 2007-7-5 22:03:20 > top of Java-index,Archived Forums,Java Programming...