What's the C++ version of Java's ArrayList

Viewed 161234

Just getting back into using C++ and trying to convert a simple Java program I wrote recently.

What's the preferred equivalent to the Java ArrayList in C++?

3 Answers

Like other answers the closest one is std::vector.

But there is one important thing to consider, space complexity.

The C++ vector has compiler dependent calculation when current capacity is full. When capacity is full some compilers grow the vector capacity exponentially and some loosely exponential.

For Java arraylist, there are no exact details specified by standards for recalculating the capacity when it is full. Some have a rough calculation of 150% plus one. But not sure if that is the exact calculation.

Related