+ 1
What is vector? How to use vector that may be vary in size?
Java
3 Réponses
+ 3
Vector is just an Object that deals with the array for you. Same with array list.
So, you can do things like:
myVector.add(ObjectName);
And it will append it to the array.
The Vectors/Arraylists use a partially filled array, when full, they create a new array of larger size and deep copy all elements over to the larger array.
+ 2
The arrayList that is resizable.
I leave you official documentation
https://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html
0
Vector and ArrayList are almost equivalent. The difference is that access to a Vector is synchronized, whereas access to an ArrayList is not. What this means is that only one thread can call methods on a Vector at a time, and there's a slight overhead in acquiring the lock; if you use an ArrayList, this isn't the case. Generally, you'll want to use an ArrayList; in the single-threaded case it's a better choice, and in the multi-threaded case, you get better control over locking. Want to allow concurrent reads? Fine. Want to perform one synchronization for a batch of ten writes? Also fine. It does require a little more care on your end, but it's likely what you want. Also note that if you have an ArrayList, you can use the Collections.synchronizedList function to create a synchronized list, thus getting you the equivalent of a Vector.
http://net-informations.com/java/col/arraylist.htm