Java Collection Knowledge Point notes (ii) __java

Source: Internet
Author: User

11. When adding elements to TreeSet, only the first element does not need to implement the comparable interface, and the objects added later must implement the comparable interface, which is not a good practice, because when an attempt is made to remove an element from the TreeSet, will still cause classexception anomalies.

12.EnumSet is stored in the form of an internal vector, which is very compact and efficient, and the Enumset collection does not allow null values to be added.

13.hash performance is always better than treeset performance (especially common additions, query elements, and so on) because TreeSet requires additional red-black tree algorithms to maintain the order of the collection elements, you should use TreeSet only if you need a set that remains sorted. Otherwise, you should use HashSet.

14.Vector has many drawbacks, and usually uses vectors to implement classes as little as possible.

The significant difference between 15.ArrayList and vector is:

ArrayList is thread insecure, and when multiple threads access a ArrayList, the programmer must manually guarantee the synchronization of the collection, but the vector collection is thread safe, so the vector is less performance than ArrayList.

16.LinkedList is a list of the implementation class, he is a list of linked list class, for sequential access to the elements of the collection optimization, in particular, insert, delete elements, due to the implementation of the Deque interface, so can be used as a stack.

17.DEque represents a "two-terminal queue", the two-end queue can simultaneously from the two-side to add, delete elements, so the implementation of deque can be used as a queue, or as a stack to use.

18.proprityQueue is a relatively standard queue implementation, and the order in which he saves the queue elements is not sorted by the order in which they were added, but by the size of the queue elements. It has violated the basic principle of the queue-first-in first Out (FIFO) and does not allow null insertion.

19.LinkedList not only provides the function of list, but also provides the function of two-terminal queue and stack.

20. Name implementation mechanism random access iterative operation insert operation delete operation

Array contiguous memory Area save element 1 does not support unsupported unsupported

    arraylist/arraydeque    to save elements in an array               2                        2                        2                        2

   vector                                     save elements with arrays       3                        3                          3                         3

  linkedlist                          two-way linked list implements element storage   4                        1                         1                           1

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.