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

C++ Equivalent to Java TreeMap

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

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

virtual void TreeMaps()
    std::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.