HashMap in java vs unordererd map in c++

Hi Everyone,

I see plenty of interview questions where HashMap is used frequently. Can I use unordered map in c++ which i guess is pretty same as hashmap in java. Or is there any other way to implement way hashmap in c++.Because I need to store some pointers in map , that is why I prefer to incline towards c++ map rather than java hashmap…!

In C++ unordered_map should work fine for this.

You may also use simply C++ STL map, but I guess map performs slower in some cases compared to unordered_map

Yes, HashMap in java and unordered_map in c++ stl are more or less the same… you can store pointers in java too(Don’t forget, in java, everything you deal with is a reference)… hence, HashMap also serves your purpose.

1 Like

plz be sure before you post your answers :wink:

thanks… :slight_smile:

sure as in?

unordered_map will do your purpose as well as hashmap in java will do . unordered map will be faster on operations like insertion and deletion than map in c++ but map possesses some extra useful characteristics such as for the elements are in sorted order , we can traverse from start to finish .