Vector collection in-depth learning

Source: Internet
Author: User

    1. Implementation method

First Vector is from JDK1.2 on the provision of List the implementation , Vector and the ArrayList is also implemented based on arrays

    1. Construction method

Create a size of Ten array, and assigns values to the Elementdata object, and the capacityincrement set to 0

    1. Insert object: Add (E)

Vectorin theAddmethod increases thesynchronizedkeyword, so this method is thread-safe, except that he andArrayListbasically the same, the difference is that when the array size is not enough, the amplification strategy is different (ifcapacityincrementGreater than0, you willobjecthe continuation of the array oh ah expand for nowsizeon the pluscapacityincrementthe value, ifcapacityincrementequals less than0, you willObjectthe size of the array is exaggerated for the existingsizeof twice times)

    1. Delete object: Remove (E)

in addition to its invocation of the removeelement method has synchronized keywords outside, and arrayList exactly the same

    1. Get a single object: Get (Index)

out of the way there's syhchronized keywords, Implementing and ArrayList same

    1. Traversing objects: iterator ()

and the ArrayList exactly the same

    1. To determine whether an object exists: contains (E)

and the ArrayList The only difference is indexOf method has synchronized Key Words

    1. Attention points

Vector is based on synchronized implemented thread-safe ArrayList , amplification methods and ArrayList slightly different, you can pass in capacityincrement to control the expansion of capacity

Vector collection in-depth learning

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.