Get all updates of Java4s
Follow Us: Email Newsletter

Difference between Arraylist and Vector in Java

Core Java » On Nov 2, 2012 { 8 Comments } By Sivateja

Hi friends, let us see the main differences between ArrayList and Vector collections, this is very important and common question in interviews for all IT people, hope you might face this question in your previous interviews ;)

Any how let us see the main differences and which is better regarding the performance

  • ArrayList and Vector both having same data structure internally, which is Array
  • Vector is by default synchronized, means at a time only one thread can access its methods from out side, where as ArrayList is non-synchronized means N number of threads can access at a time
  • But we can make ArrayList as synchronized by using Collections class, see it bellow
  • Both Vector and ArrayList  have capability to re-size dynamically, means Vector will Doubles the size of its array when its size increased, but ArrayList increased by Half only :-)

How to make ArrayList Synchronized

As we discussed above ArrayList is not synchronized by default, so will see how to make it as Synchronized.

We have direct method in Collections class to make ArrayList synchronized..

ArrayList vs Vector Speed and Performance Differences

Always ArrayList will shows better performance compared to Vector,  except Synchronization both are almost same in their performance.  Vector is Synchronized means thread safe, only 1 thread can access so its very slow compared to ArrayList, because in our real time projects we should not require synchronized methods always.

What am saying is always try to use ArrayList rather Vector if its not required any Synchronization in your requirements,  even if so you know how to make ArrayList as synchronized right (just like above).


You Might Also Like

  ♦ About Author ♦

Full Stack( Java/J2EE & UI/UX ) Developer and founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog. Sign-up for the Email Newsletter for your daily dose of Java tutorials.


8 Responses to “Difference between Arraylist and Vector in Java”
  1. Naresh says:

    If we synchronize arraylist,which is very poor in performance right?please explain me why?

  2. Rajesh Yadav says:

    If We Can Synchornize ArrayList , then what is the use of Vector? which Senario we use the vector then?

  3. vasanth says:

    what is the Advantage of default initial capacity in ArrayList?

  4. Surya says:

    What are the initial sizes for both ArrayList & Vector ?

  5. Rajkumar says:

    what is the default capacity in vector ?

  6. kumar says:

    How to generate the Barcode in jsp. please send me sample application using to eclipse?

  7. ravi says:

    Hi ,

    please code for spring mvc with hibernate for CRUD operations

  8. Saurabh Ranjan says:

    Can we make arraylist as synchronized?If yes,what is the use of Vector ?


By posting your answer, you agree to our comments policy.
What would you like to learn today?
Browse these popular technologies
Hibernate spring struts Servlets ajax Log4j jQuery Json Core Java Web Services AngularJs
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
Useful Links Current & UpComing Tutorials
  Web Services [ SOAP ], JSP
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2016 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.