• Saves Valuable Time
  • Trusted Accuracy since 2004
  • 15-Day Money-Back Guarantee

C++ Equivalent to Java HashMap

The nearly exact C++ equivalent to Java's HashMap collection is the std::unordered_map collection.

Java C++
void HashMaps()
    java.util.HashMap<String, Integer> map = new java.util.HashMap<String, Integer>();
    String s = "test";
    map.put(s, 1);
    int i = map.get(s);
    i = map.size();
    boolean b = map.isEmpty();
#include <string>
#include <unordered_map>

virtual void HashMaps()
    std::unordered_map<std::wstring, int> map;
    std::wstring s = L"test";
    map.emplace(s, 1);
    int i = map[s];
    i = map.size();
    bool b = map.empty();

Use Java to C++ Converter to convert from Java to C++.     

Additional resource: Java and C++ Equivalents

Copyright © 2004 – 2021 Tangible Software Solutions, Inc.