Hi,
I have another question.
What is the advantage of arraylist over vector.
Why arraylist is widely used instead of vector in java programming?
Thanks in advance.....

don't use Vector unless you have to and remember that you don't have to unless you've no other option (like it's a required argument to some method). That's all you need to know.

may be it is a legacy class. but I was asked both the questions in Interview.
That is why I need to know the answers.

Well in relation to threads, I major difference is that a Vector is synchronized and an ArrayList is not synchronized. What this means is, if two threads attempt to access a
Vector it will be synchronized. One thread will have to wait until the
other thread is finished accessing the Vector. With an ArrayList you have
to create wrappers to synchronize access to the ArrayList or you will have
undefined behaviour.

Also:

http://forum.java.sun.com/thread.jspa?threadID=715808&messageID=4136184

may be it is a legacy class. but I was asked both the questions in Interview.
That is why I need to know the answers.

If you were asked that in a job interview and didn't know the answer they're right to fail you.
If you applied for a job where you should know the answer and you not only don't know it but don't know where to find it (and it's easy to find, everyone should know who's programmed in Java for more than a day or so) you don't deserve any job at all.

Nice Answer Jwenting,

You are obviously an asshole and don't deserve any friends.

In answer to the original question. The main reason is that Vector is internally synchronized and so if you aren't using threads then you have an unnecessary performance hit. Also, internal synchronization is not very good for managing data concurrently (not very thread-safe) so even when it should be used you shouldn't use Vector but rather an ArrayList in conjunction with a concurrency class.

Hope this helps. Good luck in those interviews.

If you were asked that in a job interview and didn't know the answer they're right to fail you.
If you applied for a job where you should know the answer and you not only don't know it but don't know where to find it (and it's easy to find, everyone should know who's programmed in Java for more than a day or so) you don't deserve any job at all.

commented: troll -2

Jwenting said probably said that because googling "vector arraylist java" returns thousands of helpful results to the exact question the OP asked. Why reiterate a question that has been answered so many times that can be found so easily? And you upping this thread was also unnecessary. Look at the date it was posted.

For example, this article, although outdated, provides enough information to answer the OP's question.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.