Java source reading vector

Source: Internet
Author: User
Tags concurrentmodificationexception

1 Types of annotations

/*** The {@codeVector} class implements a growable array of * objects. Like a array, it contains components that can is * accessed using an integer index. However, the size of a * {@codeVector} can grow or shrink as needed to accommodate * adding and removing items after the {@codeVector} has been created. * * <p>each vector tries to optimize storage management by maintaining a * {@codecapacity} and a {@codecapacityincrement}. The * {@codeCapacity} is always at least as large as the vector * size;  It is usually larger because as a components be added to the vector, the vector's storage increases in chunks the size of * {@codecapacityincrement}. An application can increase the * capacity of a vector before inserting a large number of * components; This reduces the amount of incremental reallocation. * * <p><a name= "Fail-fast" > * The iterators returned by this class ' s {@link#iterator () iterator} and * {@link#listIterator (int) Listiterator} methods be <em>fail-fast</em></a>: * If the vector is structural Ly modified at no time after the iterator are * created, in any except through the iterator ' s own * {@linklistiterator#remove () remove} or * {@linkListiterator#add (Object) Add} methods, the iterator would throw a * {@linkconcurrentmodificationexception}. Thus, in the face of * concurrent modification, the iterator fails quickly and cleanly, rather * than risking arbitrary, n  On-deterministic behavior at a undetermined * time in the future. The {@linkenumeration Enumerations} returned by * The {@link#elements () elements} method is <em>not</em> fail-fast. * * <p>note that the fail-fast behavior of a iterator cannot be guaranteed * as it is, generally speaking, impossib  Guarantees in the * presence of unsynchronized concurrent modification. Fail-fast iterators * Throw {@codeconcurrentmodificationexception} on a best-effort basis. * Therefore, it would is wrong to the write a program the depended on the this * exception for its correctness: <i>the FAI L-fast behavior of iterators * should be used only to detect bugs.</i> * * <p>as of the Java 2 platform v1.2, This class is retrofitted to * implement the {@linkList} interface, making it a member of the * <a href= "{@Docroot}/..  /technotes/guides/collections/index.html "> * Java collections Framework</a>. Unlike the new collection * implementations, {@codeVector} is synchronized. If a thread-safe * implementation is not needed, it's recommended to use {@link* ArrayList} in place of {@codeVector}.
*/

The vector class implements a scalable array of objects. As well as arrays, the components inside him can be accessed by an integer-type index. The difference is that when a vector is created, when an item is added or deleted, its size can grow or shrink to accommodate the size.

Each vector attempts to optimize storage management by maintaining capacity and capacityincrement. Capacity is always at least as large as the size of a vector, and it is usually larger because the component adds "Capacityincrement" to the vector,vector of the storage block. An application can increase the capacity of a vector before inserting a large number of components, which reduces the amount of incremental redistribution.

The iterator returned by the iterator () and listiterator (int) Methods of the class are fail-fast (fast failure mechanism):

When iterator is created, if the structure of the vector is modified at any time, in addition to using Iterator's own listiterator#remove () or any method outside of Listiterator#add (Object), A Concurrentmodificationexception exception will be thrown. As a result, iterators can fail quickly and cleanly in the face of concurrent modifications, rather than risky behavior at some uncertain time in the future. The enumeration returned by the elements () method is not fail-fast.

It is noteworthy that the fail-fast behavior may not be guaranteed. Therefore, it is wrong to write a program that relies on the concurrentmodificationexception exception: the fail-fast behavior of the iterator should only be used to detect errors.

In the Java 2 release, this class was modified to implement the list interface, making it a member of the Java Collection framework. Vectors are synchronized ( thread-safe), and if you do not require thread-safe implementations, we recommend that you use ArrayList. (Higher efficiency)

2

Java source reading 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.