ArrayList VS Vector

Source: Internet
Author: User
This problem first looks at the common denominator:
  1. The positions of the elements stored in these two collections are ordered, equivalent to a dynamic array that can be taken out of an element by position
  2. Implements the list interface
  3. The elements in the collection allow duplicates
  4. You can set the initial space size
Difference:
  1. Thread Safety
  2. Data growth
If there is only one thread routines access to the collection, it is best to use ArrayList, because it does not consider thread safety, it is more efficient if there are multiple lines routines access to the collection, it is better to use vectors, because we do not need to consider and write thread-safe code (note: for vector &arraylist, Hashtable&hashmap, to remember the thread safety issues, remember that vectors and Hashtable are old, Java is provided in the birth, they are thread-safe, ArrayList and HashMap are provided at JAVA2, and they are thread insecure. So, we talk about the old first class. The vector grows by default to twice times the original, and can also be set to increase the size of the space ArrayList is 1.5 times times the original, and does not provide a way to set the growth space: vector, thread-safe, carefree, extravagant, free. ArrayList, efficiency first, careful, step-by-step, and all-out.

ArrayList VS Vector

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.