Java arrayList vs. C++ vector

15,492

The answer is two-fold: Firstly, you cannot compare utility classes between C++ and Java like that - different languages come with different cultures, naming conventions etc. If there was a Vector class in a C++ library, there's no connection whatsoever to any Vector class in Java, except for the name.

Secondly, the Vector class in Java is in practice deprecated, and I would discourage you from using it. In fact, forget about it :) The combination of List and ArrayList is the way to go. Use interfaces where you can, say:

List myList = new ArrayList();

Example deliberately missing generic typing.

Share:
15,492
user1136342
Author by

user1136342

Updated on June 14, 2022

Comments

  • user1136342
    user1136342 almost 2 years

    Possible Duplicate:
    What's the C++ version of Java's ArrayList

    I was reading a book called "Cracking the Coding Interview" and most (all?) of the code is in Java and arrayList is used a lot. During an interview, would using a vector instead of arrayList be acceptable if the language is C++? I'm asking because I haven't seen even one example of C++ code for similar questions using a vector but I'm not sure if there's a significant difference or not.

    And is there also an equivalent in C?