Synchronise Hashmap

I got a ClassCast Exception for this..How to correct it?
Hashmap m = (HashMap)Collections.synchronizedMap(new HashMap(...));

Basically I need a synchronise Hashmap.
Or anyone else can suggest a type that can perform better then Hashmap and provide synchronisation..
LVL 9
william007Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
Its a Map., not a HashMap. there is no such thing as a synchonized Hashmap.
use:

Map m = Collections.synchronizedMap(new HashMap(...));

anotyher option would be to use a Hashtable. It is synchronised.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
william007Author Commented:
For Map and HashTable, may I know which performance is better?
sriki77Commented:
HashMap is faster than Hashtable, because of lack of sychronization.

The synchronized Map and Hashtable performance can be comparable. No clear winner here.

As suggested use Hashtable when you need sychronized option always. Use the sychnonized Map when you want both sychonization from some access and no synchronization for certain access
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

Mick BarryJava DeveloperCommented:
> For Map and HashTable, may I know which performance is better?

Hashtable is most likely faster than a synchnozied wrapper around  a HashMap.
Mayank SAssociate Director - Product EngineeringCommented:
Yes, it is, just like we told you in your other Q that a Vector is faster than a synchronized wrapper over an array-list.
Mayank SAssociate Director - Product EngineeringCommented:
william007Author Commented:
Thanks:-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.