what is the difference between ArrayList and Vector

Answers were Sorted based on User's Feedback



what is the difference between ArrayList and Vector..

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

what is the difference between ArrayList and Vector..

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

what is the difference between ArrayList and Vector..

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

what is the difference between ArrayList and Vector..

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

what is the difference between ArrayList and Vector..

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

what is the difference between ArrayList and Vector..

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

what is the difference between ArrayList and Vector..

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

what is the difference between ArrayList and Vector..

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

what is the difference between ArrayList and Vector..

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

Post New Answer

More Core Java Interview Questions

Difference between a Scrollbar and a ScrollPane?

1 Answers  


How to create an immutable class?

0 Answers  


How do you sort objects in java?

0 Answers  


What is casting?

5 Answers  


What is Applet Flickering ?

1 Answers   Infosys, Persistent,






Difference between comparator and comparable in java?

0 Answers  


What collections you have worked on? Internal working of Hashmap?

1 Answers   Bravura Solutions,


Give a brief description of java socket programming?

0 Answers  


solve this is my problem byte a=40,byte b=50 both add value is 90 this is with in range of byte... byte range is -128to 127.... why this pgm gives error like type mismatch.... package javapgms; public class byte1 { public static void main(String args[]) { byte a=40,b=50; byte c=a+b; System.out.println(c); } } note : dont use int k... a,b,c are in byte range... mind it..

2 Answers  


I Have a class abstract with one abstract method, so that method should override in the subclass, but i dont want to override, if i am not override what will happen? If compilation will occur then i dont want to give compilation error, then what we need to do??? See the sample program. public abstract class AbstractExample { public abstract void sampleMethod(); } public class AbstractExampleImple extends AbstractExample { }

2 Answers   Mphasis,


Can I overload to string method

0 Answers   UHG,


Is array synchronized in java?

0 Answers  


Categories