what is the difference between ArrayList and Vector
Answers were Sorted based on User's Feedback
Answer / ganesh nagalingam
I am adding some more points to the above answers.
Array list and Vector have one in common. They both
implement Random Access.
It is possible to provide synchronization using Array List
by using the utility methods in Collection.
Is This Answer Correct ? | 12 Yes | 7 No |
Answer / payel
I would like to answer this question as point...which would be easier to remember
1.Vector is synchronized whereas an arraylist is not synchronized
2.Vector is an object whereas an arraylist is a part of the collection framework
3.Vector has a default size of 10 whereas an arraylist has no default size
4.Vector requires an iterator to display its contents whereas an arraylist does not require any iterator
5.Vector defines an increment size whereas an arraylist does not define any increment size
Is This Answer Correct ? | 5 Yes | 0 No |
Answer / tamilvendan
import java.util.*;
public class VectorDemo{
public static void main(String[] args){
Vector<Object> vector = new Vector<Object>();
int primitiveType = 10;
Integer wrapperType = new Integer(20);
String str = "tapan joshi";
vector.add(primitiveType);
vector.add(wrapperType);
vector.add(str);
vector.add(2, new Integer(30));
System.out.println("the elements of vector: " + vector);
System.out.println("The size of vector are: " +
vector.size());
System.out.println("The elements at position 2 is: " +
vector.elementAt(2));
System.out.println("The first element of vector is: " +
vector.firstElement());
System.out.println("The last element of vector is: " +
vector.lastElement());
vector.removeElementAt(2);
Enumeration e=vector.elements();
System.out.println("The elements of vector: " + vector);
while(e.hasMoreElements()){
System.out.println("The elements are: " +
e.nextElement());
}
}
}
Is This Answer Correct ? | 7 Yes | 4 No |
Answer / rama krishna dwadasi
VECTOR:
i)Vector is a legacy class and represents array data structure.
ii)Vector uses indexing notation to store values.
iii)Vector can grow and shrink dynamically.
iv)Vector is synchronized; multiple threads cannot access
the vector object concurrently. Only one thread can access
the Vector object at a specific time.
v)Duplicate values are allowed.
vi)Before to java 2 there was an interface called
Enumeration to visit the elements of Vector. But now we have
two interfaces to visit the elements of Vector. They are
Iterator and ListIterator.
vii) Vector elements can be accessed randomly because it
implements RandomAccess marker interface
viii) Values will be stored in the same order as inserted.
ix) The elements in Vector can be accessed by Enumeration,
Iterator and ListIterator.
ArrayList:
i)ArrayList is a new class used to store multiple objects.
ii)ArrayList uses array data structure internally to store
the elements.
iiiArrayList uses indexing notation to store
values(sequentially).
iv)ArrayList can grow and shrink dynamically.
v)Duplicate values are allowed.
vi)ArrayList is not synchronized.
vii)ArrayList elements can be accessed randomly because it
implements RandomAccess marker interface.
viii)Values will be stored in the same order as inserted.
ix)The elements in ArrayList can be accessed by Iterator and
ListIterator.
Is This Answer Correct ? | 4 Yes | 1 No |
Answer / vishu
In the above examples, need to change one thing. i.e
e. If you try to set v.ensureCapacity( >10), then
f. V.capacity();===20
if we put value between 11 to 20, the capacity will be 20,
after that it will increase if greater than 20.
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / janardhan
ArrayList contains all methods are non-synchronized methods.
ArrayList by default not threadsafe.
ArrayList allows duplicate objects.
ArrayList default size is 16.if you want to increase size
use this formula:-- defaultsize * 3/2 + 1.
we can make araylist as synchronised:--
List l=Collections.SynchronizedList(new arrayList());
Arraylist is best choice for retrival operation and worest
choice for insert operation.
Vector:--
Vector is same like arraylist, but we have only one
difference is vector contains all synchronized methods.
Vector is best choice for retrival operation and worest
choice for insert operation.
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / kishore kumar naidu n
ArrayList Vector
1>. NOT synchronized 1>.Synchronized by Default
2>. Use only Iterator to 2>.Can use Iterator and Enumerator
access elements interface to access elements
3>. It increase it's size 3>.Default it double it's size
by 50% if it run out
off room
4>. No default size 4>.Default size is 10.
Is This Answer Correct ? | 2 Yes | 0 No |
Answer / mallikarjuna
yes ArrayList is not syncronized on multiple threads and
not give correct result but Vector is syncronized 0n
multiple threads and it give correct result
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / subha
What is the intial buffer size of arraylist?
public Vector() {
this(10);
}
if u check v.capacity(),it'l display the buffer size of vector.
like i need a program to find intial buffer size of arraylist.
plz see java class for arraylist.
public ArrayList() {
this(10);
}
if anyone knows about this one.plz post the comment.
Is This Answer Correct ? | 0 Yes | 0 No |
What are autoboxing and unboxing? When does it occur?
How many bits are allocated to represent character of character sets - Unicode, ASCII, UTF-16, UTF-8?
types of applets?.
What is the difference between member variables initialization and assignment in a constructor?
What is a method in programming?
What is the difference between a public and a non-public class?
What is use of valueof () in java?
Can we convert integer to string in java?
Describe what happens when an object is created in java ?
program to find 25 square = 625 here the 625 of last two digits is equal to 25, i don't know excatly what this type of number is called
What is class and its types?
What is Java Classloader?
1 Answers Phantom Technologies,