Differences? You cannot compare how 2 languages do those. Normally Vector
do use Stack data structure or LinkedList (or may be both). Which means, you put one item to the top, put another item on top of it, another item even on top of it, like wise. In LinkedList, it is bit different, you "pull" the value but the same thing. So in C++ it is better to use push_back()
method.
C++ Vector objects are instantiated automatically. But in Java it is not, you have to fill it. I disagree with the way of filling it using l5.add(1, "Test");
. Use l5.add("test")
.
Since you asked differences, you can define your object in this way as well
Vector a = new Vector();
That is without a type, in Java we call it without Generics
. Possible since Java 1.6
Vector is now not widely used in Java. It has delays. We now move with ArrayList
which is inside List
interface.
Edit
variable names such as l5
are widely used in C++. But Java community expects more meaningful variable names :)