Jdk sequence table notes and jdk sequence notes

Source: Internet
Author: User

Jdk sequence table notes and jdk sequence notes
1. AbstractCollection provides the maximum implementation of the Set to inherit this class. size () and iterator () must be implemented (), because the operation sets are all implemented through iterator 2 and fail-fast policies, this policy is applied multiple times in the Collection framework with a multi-thread to protect the same set of operations, ensure that the operation target has not been operated by other threads. Similar to the cas idea, the specific implementation in the set is: defining a global variable modCount, indicates the number of times the set is modified. During each dynamic operation, modCount ++ defines a global variable expectedModCount in the Iterator. modCount and expectedModCount are compared during each operation of the Iterator, if the set is equal, the set is not modified concurrently. Otherwise, ConcurrentModificationException will be thrown. As long as the variable modCount exists, the thread is not secure. It is best to use the iterator for this set, because direct operations do not check whether the set has been concurrently modified using volatile to modify the modCount variable modified by volatile, the processor reads the value from the memory (shared memory) for each reference in the program, instead of getting it from registers (memory exclusive to the thread), this makes the fail-fast policy more reliable. 3. AbstractList provides the maximum implementation of the sequence table and implements the iterator to inherit the class, the get method needs to be implemented, because the next of the iterator calls get 4, ArrayList1. the initial capacity is 10 Constructor (SET) and addAll, which is a deep copy, because it calls AbstractCollection. toArray () ----> Arrays. copyOf () ------> System. arraycopy () 2. trimToSize is used for multiple purposes. Because when a sequence table is created, an array of the initial size will be created, so that there will be no space. You can call this method to clear unnecessary positions, the actual space-saving length is the length of the storage array, not the size of the global variable. size means that multiple elements have data. 3. by default, the extended capacity is increased by half. int overflow (overflow <0) should be considered, and the maximum memory of the virtual machine must use ensureCapacity (int minSize). When the capacity needs to be increased, make sure that the capacity is supported. Otherwise, the capacity will be extended to prevent array overflow. toArray and clone are all deep copies. the maintained array does not have a generic type. If you need to obtain elements, You need to transform it. 6. dynamic operations do not look like books with common data structures. Instead, you need to move the subsequent nodes of the operation elements, but directly copy a copy. after developing a good habit of dynamic operations, we should not only move the pointer, but also set the Nonexistent element location to null to make the Garbage Collector work 8. provides some low-security, but fast private methods such as remove (Obj). After obtaining the subscript, you can call a fastRemove (index) without the need for a second comparison value of 9. subList (from, to) returns the view of the set. The view is a shortest copy and will directly operate on the set.

View Original: http://blog.zswlib.com/2016/10/26/jdk%e9%a1%ba%e5%ba%8f%e8%a1%a8%e7%ac%94%e8% AE %b0/

Related Article

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.